Class PGPKeyPairGenerator
java.lang.Object
org.bouncycastle.openpgp.operator.PGPKeyPairGenerator
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final Date
protected final KeyFingerPrintCalculator
protected SecureRandom
protected final int
-
Constructor Summary
ConstructorsConstructorDescriptionPGPKeyPairGenerator
(int version, Date creationTime, SecureRandom random, KeyFingerPrintCalculator fingerPrintCalculator) Create an instance of the key pair generator. -
Method Summary
Modifier and TypeMethodDescriptionabstract PGPKeyPair
generateECDHKeyPair
(org.bouncycastle.asn1.ASN1ObjectIdentifier curveOID) Generate an elliptic curve Diffie-Hellman encryption key pair over the curve identified by the given OID.abstract PGPKeyPair
generateECDSAKeyPair
(org.bouncycastle.asn1.ASN1ObjectIdentifier curveOID) Generate an elliptic curve signing key over the curve identified by the given OID.abstract PGPKeyPair
Generate an elliptic curve signing key over the twisted Edwards curve25519.abstract PGPKeyPair
Generate an elliptic curve signing key over the twisted Edwards curve448.Generate an encryption subkey.abstract PGPKeyPair
Generate a legacy elliptic curve signing key pair over the twisted Edwards curve25519.abstract PGPKeyPair
Generate a legacy elliptic curve Diffie-Hellman encryption key pair over curve25519.Generate an ECDH elliptic curve encryption key over the NIST p-256 curve.Generate an ECDSA elliptic curve signing key over the NIST p-256 curve.Generate an ECDH elliptic curve encryption key over the NIST p-384 curve.Generate an ECDSA elliptic curve signing key over the NIST p-384 curve.Generate an ECDH elliptic curve encryption key over the NIST p-521 curve.Generate an ECDSA elliptic curve signing key over the NIST p-521 curve.Generate a primary key.generateRsaKeyPair
(int bitStrength) Generate a RSA key pair with the given bit-strength.abstract PGPKeyPair
generateRsaKeyPair
(BigInteger exponent, int bitStrength) Generate a RSA key pair with the given bit-strength over a custom exponent.Generate a signing subkey.abstract PGPKeyPair
Generate an elliptic curve Diffie-Hellman encryption key over curve25519.abstract PGPKeyPair
Generate an elliptic curve Diffie-Hellman encryption key over curve448.
-
Field Details
-
creationTime
-
version
protected final int version -
random
-
fingerPrintCalculator
-
-
Constructor Details
-
PGPKeyPairGenerator
public PGPKeyPairGenerator(int version, Date creationTime, SecureRandom random, KeyFingerPrintCalculator fingerPrintCalculator) Create an instance of the key pair generator.- Parameters:
version
- public key version (PublicKeyPacket.VERSION_4
orPublicKeyPacket.VERSION_6
).creationTime
- key creation timerandom
- secure random number generator
-
-
Method Details
-
generatePrimaryKey
Generate a primary key. A primary key MUST use a signing-capable public key algorithm.- Returns:
- primary key pair
- Throws:
PGPException
- if the key pair cannot be generated
-
generateEncryptionSubkey
Generate an encryption subkey. An encryption subkey MUST use an encryption-capable public key algorithm.- Returns:
- encryption subkey pair
- Throws:
PGPException
- if the key pair cannot be generated
-
generateSigningSubkey
Generate a signing subkey. A signing subkey MUST use a signing-capable public key algorithm.- Returns:
- signing subkey pair
- Throws:
PGPException
- if the key pair cannot be generated
-
generateRsaKeyPair
Generate a RSA key pair with the given bit-strength. It is recommended to use at least 2048 bits or more. The key will be generated over the default exponent65537
. RSA keys are deprecated for OpenPGP v6.- Parameters:
bitStrength
- strength of the key pair in bits- Returns:
- rsa key pair
- Throws:
PGPException
- if the key pair cannot be generated
-
generateRsaKeyPair
public abstract PGPKeyPair generateRsaKeyPair(BigInteger exponent, int bitStrength) throws PGPException Generate a RSA key pair with the given bit-strength over a custom exponent. It is recommended to use at least 2048 bits or more. RSA keys are deprecated for OpenPGP v6.- Parameters:
exponent
- RSA exponente
bitStrength
- strength of the key pair in bits- Returns:
- rsa key pair
- Throws:
PGPException
- if the key pair cannot be generated
-
generateEd25519KeyPair
Generate an elliptic curve signing key over the twisted Edwards curve25519. The key will usePublicKeyAlgorithmTags.Ed25519
which was introduced with RFC9580. For legacy Ed25519 keys usegenerateLegacyEd25519KeyPair()
.- Returns:
- Ed25519 key pair
- Throws:
PGPException
- if the key pair cannot be generated- See Also:
-
generateEd448KeyPair
Generate an elliptic curve signing key over the twisted Edwards curve448. The key will usePublicKeyAlgorithmTags.Ed448
which was introduced with RFC9580.- Returns:
- Ed448 signing key pair
- Throws:
PGPException
- if the key pair cannot be generated- See Also:
-
generateX25519KeyPair
Generate an elliptic curve Diffie-Hellman encryption key over curve25519. THe key will usePublicKeyAlgorithmTags.X25519
which was introduced with RFC9580. For legacy X25519 keys usegenerateLegacyX25519KeyPair()
instead.- Returns:
- X25519 encryption key pair
- Throws:
PGPException
- if the key pair cannot be generated- See Also:
-
generateX448KeyPair
Generate an elliptic curve Diffie-Hellman encryption key over curve448. THe key will usePublicKeyAlgorithmTags.X448
which was introduced with RFC9580.- Returns:
- X448 encryption key pair
- Throws:
PGPException
- if the key pair cannot be generated- See Also:
-
generateLegacyEd25519KeyPair
Generate a legacy elliptic curve signing key pair over the twisted Edwards curve25519. Legacy keys have good application support, but MUST NOT be used as OpenPGP v6 keys. The key will usePublicKeyAlgorithmTags.EDDSA_LEGACY
as algorithm ID. For OpenPGP v6 (RFC9580) usegenerateEd25519KeyPair()
instead.- Returns:
- legacy Ed25519 key pair
- Throws:
PGPException
- if the key pair cannot be generated- See Also:
-
generateLegacyX25519KeyPair
Generate a legacy elliptic curve Diffie-Hellman encryption key pair over curve25519. Legacy keys have good application support, but MUST NOT be used as OpenPGP v6 keys. The key will usePublicKeyAlgorithmTags.ECDH
as algorithm ID. For OpenPGP v6 (RFC9580) usegenerateX25519KeyPair()
instead.- Returns:
- legacy X25519 key pair
- Throws:
PGPException
- if the key pair cannot be generated
-
generateNistP256ECDHKeyPair
Generate an ECDH elliptic curve encryption key over the NIST p-256 curve.- Returns:
- NIST p-256 ECDSA encryption key pair
- Throws:
PGPException
- if the key pair cannot be generated- See Also:
-
generateNistP384ECDHKeyPair
Generate an ECDH elliptic curve encryption key over the NIST p-384 curve.- Returns:
- NIST p-384 ECDSA encryption key pair
- Throws:
PGPException
- if the key pair cannot be generated- See Also:
-
generateNistP521ECDHKeyPair
Generate an ECDH elliptic curve encryption key over the NIST p-521 curve.- Returns:
- NIST p-521 ECDSA encryption key pair
- Throws:
PGPException
- if the key pair cannot be generated- See Also:
-
generateNistP256ECDSAKeyPair
Generate an ECDSA elliptic curve signing key over the NIST p-256 curve.- Returns:
- NIST p-256 ECDSA signing key pair
- Throws:
PGPException
- if the key pair cannot be generated- See Also:
-
generateNistP384ECDSAKeyPair
Generate an ECDSA elliptic curve signing key over the NIST p-384 curve.- Returns:
- NIST p-384 ECDSA signing key pair
- Throws:
PGPException
- if the key pair cannot be generated- See Also:
-
generateNistP521ECDSAKeyPair
Generate an ECDSA elliptic curve signing key over the NIST p-521 curve.- Returns:
- NIST p-521 ECDSA signing key pair
- Throws:
PGPException
- if the key pair cannot be generated- See Also:
-
generateECDHKeyPair
public abstract PGPKeyPair generateECDHKeyPair(org.bouncycastle.asn1.ASN1ObjectIdentifier curveOID) throws PGPException Generate an elliptic curve Diffie-Hellman encryption key pair over the curve identified by the given OID.- Parameters:
curveOID
- OID of the elliptic curve- Returns:
- PGP key pair
- Throws:
PGPException
- if the key pair cannot be generated
-
generateECDSAKeyPair
public abstract PGPKeyPair generateECDSAKeyPair(org.bouncycastle.asn1.ASN1ObjectIdentifier curveOID) throws PGPException Generate an elliptic curve signing key over the curve identified by the given OID.- Parameters:
curveOID
- OID of the elliptic curve- Returns:
- PGP key pair
- Throws:
PGPException
- if the key pair cannot be generated
-