Skip to content

Commit c17f979

Browse files
committed
Add javadoc to PGPKeyPairGenerator
1 parent cfcd237 commit c17f979

File tree

1 file changed

+90
-3
lines changed

1 file changed

+90
-3
lines changed

pg/src/main/java/org/bouncycastle/openpgp/operator/PGPKeyPairGenerator.java

+90-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.bouncycastle.openpgp.operator;
22

3+
import org.bouncycastle.bcpg.PublicKeyAlgorithmTags;
34
import org.bouncycastle.openpgp.PGPException;
45
import org.bouncycastle.openpgp.PGPKeyPair;
56

@@ -14,6 +15,14 @@ public abstract class PGPKeyPairGenerator
1415
protected final int version;
1516
protected SecureRandom random;
1617

18+
/**
19+
* Create an instance of the key pair generator.
20+
*
21+
* @param version public key version ({@link org.bouncycastle.bcpg.PublicKeyPacket#VERSION_4}
22+
* or {@link org.bouncycastle.bcpg.PublicKeyPacket#VERSION_6}).
23+
* @param creationTime key creation time
24+
* @param random secure random number generator
25+
*/
1726
public PGPKeyPairGenerator(int version, Date creationTime, SecureRandom random)
1827
{
1928
this.creationTime = new Date((creationTime.getTime() / 1000) * 1000);
@@ -26,7 +35,7 @@ public PGPKeyPairGenerator(int version, Date creationTime, SecureRandom random)
2635
* A primary key MUST use a signing-capable public key algorithm.
2736
*
2837
* @return primary key pair
29-
* @throws PGPException
38+
* @throws PGPException if the key pair cannot be generated
3039
*/
3140
public PGPKeyPair generatePrimaryKey()
3241
throws PGPException
@@ -39,7 +48,7 @@ public PGPKeyPair generatePrimaryKey()
3948
* An encryption subkey MUST use an encryption-capable public key algorithm.
4049
*
4150
* @return encryption subkey pair
42-
* @throws PGPException
51+
* @throws PGPException if the key pair cannot be generated
4352
*/
4453
public PGPKeyPair generateEncryptionSubkey()
4554
throws PGPException
@@ -52,38 +61,116 @@ public PGPKeyPair generateEncryptionSubkey()
5261
* A signing subkey MUST use a signing-capable public key algorithm.
5362
*
5463
* @return signing subkey pair
55-
* @throws PGPException
64+
* @throws PGPException if the key pair cannot be generated
5665
*/
5766
public PGPKeyPair generateSigningSubkey()
5867
throws PGPException
5968
{
6069
return generateEd25519KeyPair();
6170
}
6271

72+
/**
73+
* Generate a RSA key pair with the given bit-strength.
74+
* It is recommended to use at least 2048 bits or more.
75+
* The key will be generated over the default exponent <pre>65537</pre>.
76+
* RSA keys are deprecated for OpenPGP v6.
77+
*
78+
* @param bitStrength strength of the key pair in bits
79+
* @return rsa key pair
80+
* @throws PGPException if the key pair cannot be generated
81+
*/
6382
public PGPKeyPair generateRsaKeyPair(int bitStrength)
6483
throws PGPException
6584
{
6685
return generateRsaKeyPair(BigInteger.valueOf(0x10001), bitStrength);
6786
}
6887

88+
/**
89+
* Generate a RSA key pair with the given bit-strength over a custom exponent.
90+
* It is recommended to use at least 2048 bits or more.
91+
* RSA keys are deprecated for OpenPGP v6.
92+
*
93+
* @param exponent RSA exponent <pre>e</pre>
94+
* @param bitStrength strength of the key pair in bits
95+
* @return rsa key pair
96+
* @throws PGPException if the key pair cannot be generated
97+
*/
6998
public abstract PGPKeyPair generateRsaKeyPair(BigInteger exponent, int bitStrength)
7099
throws PGPException;
71100

101+
/**
102+
* Generate an elliptic curve signing key over the twisted Edwards curve25519.
103+
* The key will use {@link PublicKeyAlgorithmTags#Ed25519} which was introduced with RFC9580.
104+
* For legacy Ed25519 keys use {@link #generateLegacyEd25519KeyPair()}.
105+
*
106+
* @see <a href="https://www.rfc-editor.org/rfc/rfc9580.html#name-public-key-algorithms">
107+
* RFC9580 - Public Key Algorithms</a>
108+
* @return Ed25519 key pair
109+
* @throws PGPException if the key pair cannot be generated
110+
*/
72111
public abstract PGPKeyPair generateEd25519KeyPair()
73112
throws PGPException;
74113

114+
/**
115+
* Generate an elliptic curve signing key over the twisted Edwards curve448.
116+
* The key will use {@link PublicKeyAlgorithmTags#Ed448} which was introduced with RFC9580.
117+
*
118+
* @see <a href="https://www.rfc-editor.org/rfc/rfc9580.html#name-public-key-algorithms">
119+
* RFC9580 - Public Key Algorithms</a>
120+
* @return Ed448 signing key pair
121+
* @throws PGPException if the key pair cannot be generated
122+
*/
75123
public abstract PGPKeyPair generateEd448KeyPair()
76124
throws PGPException;
77125

126+
/**
127+
* Generate an elliptic curve Diffie-Hellman encryption key over curve25519.
128+
* THe key will use {@link PublicKeyAlgorithmTags#X25519} which was introduced with RFC9580.
129+
* For legacy X25519 keys use {@link #generateLegacyX25519KeyPair()} instead.
130+
*
131+
* @see <a href="https://www.rfc-editor.org/rfc/rfc9580.html#name-public-key-algorithms">
132+
* RFC9580 - Public Key Algorithms</a>
133+
* @return X25519 encryption key pair
134+
* @throws PGPException if the key pair cannot be generated
135+
*/
78136
public abstract PGPKeyPair generateX25519KeyPair()
79137
throws PGPException;
80138

139+
/**
140+
* Generate an elliptic curve Diffie-Hellman encryption key over curve448.
141+
* THe key will use {@link PublicKeyAlgorithmTags#X448} which was introduced with RFC9580.
142+
*
143+
* @see <a href="https://www.rfc-editor.org/rfc/rfc9580.html#name-public-key-algorithms">
144+
* RFC9580 - Public Key Algorithms</a>
145+
* @return X448 encryption key pair
146+
* @throws PGPException if the key pair cannot be generated
147+
*/
81148
public abstract PGPKeyPair generateX448KeyPair()
82149
throws PGPException;
83150

151+
/**
152+
* Generate a legacy elliptic curve signing key pair over the twisted Edwards curve25519.
153+
* Legacy keys have good application support, but MUST NOT be used as OpenPGP v6 keys.
154+
* The key will use {@link PublicKeyAlgorithmTags#EDDSA_LEGACY} as algorithm ID.
155+
* For OpenPGP v6 (RFC9580) use {@link #generateEd25519KeyPair()} instead.
156+
*
157+
* @see <a href="https://datatracker.ietf.org/doc/html/draft-koch-eddsa-for-openpgp-04">
158+
* Legacy Draft: EdDSA for OpenPGP</a>
159+
* @return legacy Ed25519 key pair
160+
* @throws PGPException if the key pair cannot be generated
161+
*/
84162
public abstract PGPKeyPair generateLegacyEd25519KeyPair()
85163
throws PGPException;
86164

165+
/**
166+
* Generate a legacy elliptic curve Diffie-Hellman encryption key pair over curve25519.
167+
* Legacy keys have good application support, but MUST NOT be used as OpenPGP v6 keys.
168+
* The key will use {@link PublicKeyAlgorithmTags#ECDH} as algorithm ID.
169+
* For OpenPGP v6 (RFC9580) use {@link #generateX25519KeyPair()} instead.
170+
*
171+
* @return legacy X25519 key pair
172+
* @throws PGPException if the key pair cannot be generated
173+
*/
87174
public abstract PGPKeyPair generateLegacyX25519KeyPair()
88175
throws PGPException;
89176
}

0 commit comments

Comments
 (0)