Class PGPKeyPairGenerator
- java.lang.Object
-
- org.bouncycastle.openpgp.operator.PGPKeyPairGenerator
-
public abstract class PGPKeyPairGenerator extends java.lang.Object
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.DatecreationTimeprotected KeyFingerPrintCalculatorfingerPrintCalculatorprotected java.security.SecureRandomrandomprotected intversion
-
Constructor Summary
Constructors Constructor Description PGPKeyPairGenerator(int version, java.util.Date creationTime, java.security.SecureRandom random, KeyFingerPrintCalculator fingerPrintCalculator)Create an instance of the key pair generator.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract PGPKeyPairgenerateEd25519KeyPair()Generate an elliptic curve signing key over the twisted Edwards curve25519.abstract PGPKeyPairgenerateEd448KeyPair()Generate an elliptic curve signing key over the twisted Edwards curve448.PGPKeyPairgenerateEncryptionSubkey()Generate an encryption subkey.abstract PGPKeyPairgenerateLegacyEd25519KeyPair()Generate a legacy elliptic curve signing key pair over the twisted Edwards curve25519.abstract PGPKeyPairgenerateLegacyX25519KeyPair()Generate a legacy elliptic curve Diffie-Hellman encryption key pair over curve25519.PGPKeyPairgeneratePrimaryKey()Generate a primary key.PGPKeyPairgenerateRsaKeyPair(int bitStrength)Generate a RSA key pair with the given bit-strength.abstract PGPKeyPairgenerateRsaKeyPair(java.math.BigInteger exponent, int bitStrength)Generate a RSA key pair with the given bit-strength over a custom exponent.PGPKeyPairgenerateSigningSubkey()Generate a signing subkey.abstract PGPKeyPairgenerateX25519KeyPair()Generate an elliptic curve Diffie-Hellman encryption key over curve25519.abstract PGPKeyPairgenerateX448KeyPair()Generate an elliptic curve Diffie-Hellman encryption key over curve448.
-
-
-
Field Detail
-
creationTime
protected final java.util.Date creationTime
-
version
protected final int version
-
random
protected java.security.SecureRandom random
-
fingerPrintCalculator
protected final KeyFingerPrintCalculator fingerPrintCalculator
-
-
Constructor Detail
-
PGPKeyPairGenerator
public PGPKeyPairGenerator(int version, java.util.Date creationTime, java.security.SecureRandom random, KeyFingerPrintCalculator fingerPrintCalculator)Create an instance of the key pair generator.- Parameters:
version- public key version (PublicKeyPacket.VERSION_4orPublicKeyPacket.VERSION_6).creationTime- key creation timerandom- secure random number generator
-
-
Method Detail
-
generatePrimaryKey
public PGPKeyPair generatePrimaryKey() throws PGPException
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
public PGPKeyPair generateEncryptionSubkey() throws PGPException
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
public PGPKeyPair generateSigningSubkey() throws PGPException
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
public PGPKeyPair generateRsaKeyPair(int bitStrength) throws PGPException
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(java.math.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
public abstract PGPKeyPair generateEd25519KeyPair() throws PGPException
Generate an elliptic curve signing key over the twisted Edwards curve25519. The key will usePublicKeyAlgorithmTags.Ed25519which was introduced with RFC9580. For legacy Ed25519 keys usegenerateLegacyEd25519KeyPair().- Returns:
- Ed25519 key pair
- Throws:
PGPException- if the key pair cannot be generated- See Also:
- RFC9580 - Public Key Algorithms
-
generateEd448KeyPair
public abstract PGPKeyPair generateEd448KeyPair() throws PGPException
Generate an elliptic curve signing key over the twisted Edwards curve448. The key will usePublicKeyAlgorithmTags.Ed448which was introduced with RFC9580.- Returns:
- Ed448 signing key pair
- Throws:
PGPException- if the key pair cannot be generated- See Also:
- RFC9580 - Public Key Algorithms
-
generateX25519KeyPair
public abstract PGPKeyPair generateX25519KeyPair() throws PGPException
Generate an elliptic curve Diffie-Hellman encryption key over curve25519. THe key will usePublicKeyAlgorithmTags.X25519which 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:
- RFC9580 - Public Key Algorithms
-
generateX448KeyPair
public abstract PGPKeyPair generateX448KeyPair() throws PGPException
Generate an elliptic curve Diffie-Hellman encryption key over curve448. THe key will usePublicKeyAlgorithmTags.X448which was introduced with RFC9580.- Returns:
- X448 encryption key pair
- Throws:
PGPException- if the key pair cannot be generated- See Also:
- RFC9580 - Public Key Algorithms
-
generateLegacyEd25519KeyPair
public abstract PGPKeyPair generateLegacyEd25519KeyPair() throws PGPException
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_LEGACYas algorithm ID. For OpenPGP v6 (RFC9580) usegenerateEd25519KeyPair()instead.- Returns:
- legacy Ed25519 key pair
- Throws:
PGPException- if the key pair cannot be generated- See Also:
- Legacy Draft: EdDSA for OpenPGP
-
generateLegacyX25519KeyPair
public abstract PGPKeyPair generateLegacyX25519KeyPair() throws PGPException
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.ECDHas algorithm ID. For OpenPGP v6 (RFC9580) usegenerateX25519KeyPair()instead.- Returns:
- legacy X25519 key pair
- Throws:
PGPException- if the key pair cannot be generated
-
-