1
1
package org .bouncycastle .openpgp .operator ;
2
2
3
+ import org .bouncycastle .bcpg .PublicKeyAlgorithmTags ;
3
4
import org .bouncycastle .openpgp .PGPException ;
4
5
import org .bouncycastle .openpgp .PGPKeyPair ;
5
6
@@ -26,7 +27,7 @@ public PGPKeyPairGenerator(int version, Date creationTime, SecureRandom random)
26
27
* A primary key MUST use a signing-capable public key algorithm.
27
28
*
28
29
* @return primary key pair
29
- * @throws PGPException
30
+ * @throws PGPException if the key pair cannot be generated
30
31
*/
31
32
public PGPKeyPair generatePrimaryKey ()
32
33
throws PGPException
@@ -39,7 +40,7 @@ public PGPKeyPair generatePrimaryKey()
39
40
* An encryption subkey MUST use an encryption-capable public key algorithm.
40
41
*
41
42
* @return encryption subkey pair
42
- * @throws PGPException
43
+ * @throws PGPException if the key pair cannot be generated
43
44
*/
44
45
public PGPKeyPair generateEncryptionSubkey ()
45
46
throws PGPException
@@ -52,38 +53,116 @@ public PGPKeyPair generateEncryptionSubkey()
52
53
* A signing subkey MUST use a signing-capable public key algorithm.
53
54
*
54
55
* @return signing subkey pair
55
- * @throws PGPException
56
+ * @throws PGPException if the key pair cannot be generated
56
57
*/
57
58
public PGPKeyPair generateSigningSubkey ()
58
59
throws PGPException
59
60
{
60
61
return generateEd25519KeyPair ();
61
62
}
62
63
64
+ /**
65
+ * Generate a RSA key pair with the given bit-strength.
66
+ * It is recommended to use at least 2048 bits or more.
67
+ * The key will be generated over the default exponent <pre>65537</pre>.
68
+ * RSA keys are deprecated for OpenPGP v6.
69
+ *
70
+ * @param bitStrength strength of the key pair in bits
71
+ * @return rsa key pair
72
+ * @throws PGPException if the key pair cannot be generated
73
+ */
63
74
public PGPKeyPair generateRsaKeyPair (int bitStrength )
64
75
throws PGPException
65
76
{
66
77
return generateRsaKeyPair (BigInteger .valueOf (0x10001 ), bitStrength );
67
78
}
68
79
80
+ /**
81
+ * Generate a RSA key pair with the given bit-strength over a custom exponent.
82
+ * It is recommended to use at least 2048 bits or more.
83
+ * RSA keys are deprecated for OpenPGP v6.
84
+ *
85
+ * @param exponent RSA exponent <pre>e</pre>
86
+ * @param bitStrength strength of the key pair in bits
87
+ * @return rsa key pair
88
+ * @throws PGPException if the key pair cannot be generated
89
+ */
69
90
public abstract PGPKeyPair generateRsaKeyPair (BigInteger exponent , int bitStrength )
70
91
throws PGPException ;
71
92
93
+ /**
94
+ * Generate an elliptic curve signing key over the twisted Edwards curve25519.
95
+ * The key will use {@link PublicKeyAlgorithmTags#Ed25519} which was introduced with RFC9580.
96
+ * For legacy Ed25519 keys use {@link #generateLegacyEd25519KeyPair()}.
97
+ *
98
+ * @see <a href="https://www.rfc-editor.org/rfc/rfc9580.html#name-public-key-algorithms">
99
+ * RFC9580 - Public Key Algorithms</a>
100
+ * @return Ed25519 key pair
101
+ * @throws PGPException if the key pair cannot be generated
102
+ */
72
103
public abstract PGPKeyPair generateEd25519KeyPair ()
73
104
throws PGPException ;
74
105
106
+ /**
107
+ * Generate an elliptic curve signing key over the twisted Edwards curve448.
108
+ * The key will use {@link PublicKeyAlgorithmTags#Ed448} which was introduced with RFC9580.
109
+ *
110
+ * @see <a href="https://www.rfc-editor.org/rfc/rfc9580.html#name-public-key-algorithms">
111
+ * RFC9580 - Public Key Algorithms</a>
112
+ * @return Ed448 signing key pair
113
+ * @throws PGPException if the key pair cannot be generated
114
+ */
75
115
public abstract PGPKeyPair generateEd448KeyPair ()
76
116
throws PGPException ;
77
117
118
+ /**
119
+ * Generate an elliptic curve Diffie-Hellman encryption key over curve25519.
120
+ * THe key will use {@link PublicKeyAlgorithmTags#X25519} which was introduced with RFC9580.
121
+ * For legacy X25519 keys use {@link #generateLegacyX25519KeyPair()} instead.
122
+ *
123
+ * @see <a href="https://www.rfc-editor.org/rfc/rfc9580.html#name-public-key-algorithms">
124
+ * RFC9580 - Public Key Algorithms</a>
125
+ * @return X25519 encryption key pair
126
+ * @throws PGPException if the key pair cannot be generated
127
+ */
78
128
public abstract PGPKeyPair generateX25519KeyPair ()
79
129
throws PGPException ;
80
130
131
+ /**
132
+ * Generate an elliptic curve Diffie-Hellman encryption key over curve448.
133
+ * THe key will use {@link PublicKeyAlgorithmTags#X448} which was introduced with RFC9580.
134
+ *
135
+ * @see <a href="https://www.rfc-editor.org/rfc/rfc9580.html#name-public-key-algorithms">
136
+ * RFC9580 - Public Key Algorithms</a>
137
+ * @return X448 encryption key pair
138
+ * @throws PGPException if the key pair cannot be generated
139
+ */
81
140
public abstract PGPKeyPair generateX448KeyPair ()
82
141
throws PGPException ;
83
142
143
+ /**
144
+ * Generate a legacy elliptic curve signing key pair over the twisted Edwards curve25519.
145
+ * Legacy keys have good application support, but MUST NOT be used as OpenPGP v6 keys.
146
+ * The key will use {@link PublicKeyAlgorithmTags#EDDSA_LEGACY} as algorithm ID.
147
+ * For OpenPGP v6 (RFC9580) use {@link #generateEd25519KeyPair()} instead.
148
+ *
149
+ * @see <a href="https://datatracker.ietf.org/doc/html/draft-koch-eddsa-for-openpgp-04">
150
+ * Legacy Draft: EdDSA for OpenPGP</a>
151
+ * @return legacy Ed25519 key pair
152
+ * @throws PGPException if the key pair cannot be generated
153
+ */
84
154
public abstract PGPKeyPair generateLegacyEd25519KeyPair ()
85
155
throws PGPException ;
86
156
157
+ /**
158
+ * Generate a legacy elliptic curve Diffie-Hellman encryption key pair over curve25519.
159
+ * Legacy keys have good application support, but MUST NOT be used as OpenPGP v6 keys.
160
+ * The key will use {@link PublicKeyAlgorithmTags#ECDH} as algorithm ID.
161
+ * For OpenPGP v6 (RFC9580) use {@link #generateX25519KeyPair()} instead.
162
+ *
163
+ * @return legacy X25519 key pair
164
+ * @throws PGPException if the key pair cannot be generated
165
+ */
87
166
public abstract PGPKeyPair generateLegacyX25519KeyPair ()
88
167
throws PGPException ;
89
168
}
0 commit comments