1 /*
2 * GordianKnot: Security Suite
3 * Copyright 2012-2026. Tony Washer
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
6 * use this file except in compliance with the License. You may obtain a copy
7 * of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14 * License for the specific language governing permissions and limitations under
15 * the License.
16 */
17 package io.github.tonywasher.joceanus.gordianknot.api.keypair;
18
19 import io.github.tonywasher.joceanus.gordianknot.api.base.GordianException;
20
21 import java.security.spec.PKCS8EncodedKeySpec;
22 import java.security.spec.X509EncodedKeySpec;
23
24 /**
25 * KeyPair Generator API.
26 */
27 public interface GordianKeyPairGenerator {
28 /**
29 * Obtain keySpec.
30 *
31 * @return the keySpec
32 */
33 GordianKeyPairSpec getKeySpec();
34
35 /**
36 * Generate a new KeyPair.
37 *
38 * @return the new KeyPair
39 */
40 GordianKeyPair generateKeyPair();
41
42 /**
43 * Extract the X509 encoding for the public key.
44 *
45 * @param pKeyPair the keyPair
46 * @return the X509 publicKeySpec
47 * @throws GordianException on error
48 */
49 X509EncodedKeySpec getX509Encoding(GordianKeyPair pKeyPair) throws GordianException;
50
51 /**
52 * Obtain PKCS8EncodedKeySpec.
53 *
54 * @param pKeyPair the keyPair
55 * @return the PrivateKeySpec
56 * @throws GordianException on error
57 */
58 PKCS8EncodedKeySpec getPKCS8Encoding(GordianKeyPair pKeyPair) throws GordianException;
59
60 /**
61 * Create the keyPair from the PKCS8/X509 encodings.
62 *
63 * @param pPublicKey the encoded public key
64 * @param pPrivateKey the secured private key
65 * @return the keyPair
66 * @throws GordianException on error
67 */
68 GordianKeyPair deriveKeyPair(X509EncodedKeySpec pPublicKey,
69 PKCS8EncodedKeySpec pPrivateKey) throws GordianException;
70
71 /**
72 * Derive the public-only keyPair from the X509 encoding.
73 *
74 * @param pPublicKeySpec the publicKeySpec
75 * @return the derived public-only keyPair
76 * @throws GordianException on error
77 */
78 GordianKeyPair derivePublicOnlyKeyPair(X509EncodedKeySpec pPublicKeySpec) throws GordianException;
79 }