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 import io.github.tonywasher.joceanus.gordianknot.api.keypair.spec.GordianKeyPairSpec;
21
22 import java.security.spec.PKCS8EncodedKeySpec;
23 import java.security.spec.X509EncodedKeySpec;
24
25 /**
26 * KeyPair Generator API.
27 */
28 public interface GordianKeyPairGenerator {
29 /**
30 * Obtain keySpec.
31 *
32 * @return the keySpec
33 */
34 GordianKeyPairSpec getKeySpec();
35
36 /**
37 * Generate a new KeyPair.
38 *
39 * @return the new KeyPair
40 */
41 GordianKeyPair generateKeyPair();
42
43 /**
44 * Extract the X509 encoding for the public key.
45 *
46 * @param pKeyPair the keyPair
47 * @return the X509 publicKeySpec
48 * @throws GordianException on error
49 */
50 X509EncodedKeySpec getX509Encoding(GordianKeyPair pKeyPair) throws GordianException;
51
52 /**
53 * Obtain PKCS8EncodedKeySpec.
54 *
55 * @param pKeyPair the keyPair
56 * @return the PrivateKeySpec
57 * @throws GordianException on error
58 */
59 PKCS8EncodedKeySpec getPKCS8Encoding(GordianKeyPair pKeyPair) throws GordianException;
60
61 /**
62 * Create the keyPair from the PKCS8/X509 encodings.
63 *
64 * @param pPublicKey the encoded public key
65 * @param pPrivateKey the secured private key
66 * @return the keyPair
67 * @throws GordianException on error
68 */
69 GordianKeyPair deriveKeyPair(X509EncodedKeySpec pPublicKey,
70 PKCS8EncodedKeySpec pPrivateKey) throws GordianException;
71
72 /**
73 * Derive the public-only keyPair from the X509 encoding.
74 *
75 * @param pPublicKeySpec the publicKeySpec
76 * @return the derived public-only keyPair
77 * @throws GordianException on error
78 */
79 GordianKeyPair derivePublicOnlyKeyPair(X509EncodedKeySpec pPublicKeySpec) throws GordianException;
80 }