Class OpenPGPKeyGenerator
java.lang.Object
org.bouncycastle.openpgp.api.AbstractOpenPGPKeySignatureGenerator
org.bouncycastle.openpgp.api.OpenPGPKeyGenerator
- Direct Known Subclasses:
BcOpenPGPKeyGenerator, JcaOpenPGPKeyGenerator
High-level generator class for OpenPGP v6 keys.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclassIntermediate builder class. -
Field Summary
Fields inherited from class AbstractOpenPGPKeySignatureGenerator
defaultAeadAlgorithmPreferences, defaultCompressionAlgorithmPreferences, defaultFeatures, defaultHashAlgorithmPreferences, defaultSymmetricKeyPreferences, directKeySignatureSubpackets, encryptionSubkeySubpackets, signingSubkeySubpackets -
Constructor Summary
ConstructorsConstructorDescriptionOpenPGPKeyGenerator(OpenPGPImplementation implementation, boolean aead, Date creationTime) OpenPGPKeyGenerator(OpenPGPImplementation implementationProvider, int version, boolean aead, Date creationTime) OpenPGPKeyGenerator(OpenPGPImplementation implementationProvider, int keyVersion, PGPKeyPairGeneratorProvider kpGenProvider, PGPDigestCalculatorProvider digestCalculatorProvider, PBESecretKeyEncryptorFactory keyEncryptionBuilderProvider, KeyFingerPrintCalculator keyFingerPrintCalculator, Date creationTime) Generate a new OpenPGP key generator for v6 keys. -
Method Summary
Modifier and TypeMethodDescriptionclassicKey(String userId) Generate an OpenPGP key consisting of a certify-only primary key, a dedicated signing-subkey and dedicated encryption-subkey.compositeRSAKey(int bitStrength, String userId) Generate an OpenPGP key composed of 3 individual component keys based on RSA of the given strength in bits.ed25519x25519Key(String userId) Generate an OpenPGP key consisting of an Ed25519 certify-only primary key, a dedicated Ed25519 sign-only subkey and dedicated X25519 encryption-only subkey.ed448x448Key(String userId) Generate an OpenPGP key consisting of an Ed448 certify-only primary key, a dedicated Ed448 sign-only subkey and dedicated X448 encryption-only subkey.Generate a post-quantum/traditional OpenPGP key as RFC 9980 specifies it: an ML-DSA-65 + Ed25519 certify-only primary key, a dedicated ML-DSA-65 + Ed25519 sign-only subkey and a dedicated ML-KEM-768 + X25519 encryption-only subkey - the two algorithms a conformant implementation MUST support.mlDsa87Ed448MlKem1024X448Key(String userId) Generate a post-quantum/traditional OpenPGP key at the higher RFC 9980 security level: an ML-DSA-87 + Ed448 certify-only primary key, a dedicated ML-DSA-87 + Ed448 sign-only subkey and a dedicated ML-KEM-1024 + X448 encryption-only subkey.Generate a sign-only OpenPGP key.singletonRSAKey(int bitStrength, String userId) Generate an OpenPGP key based on a single, multipurpose RSA key of the given strength.Generate a post-quantum OpenPGP key with fast hash-based signatures: an SLH-DSA-SHAKE-128f certify-only primary key, a dedicated SLH-DSA-SHAKE-128f sign-only subkey and a dedicated ML-KEM-768 + X25519 encryption-only subkey (the combination of RFC 9980 Appendix A.6).Generate a post-quantum OpenPGP key with hash-based signatures: an SLH-DSA-SHAKE-128s certify-only primary key, a dedicated SLH-DSA-SHAKE-128s sign-only subkey and a dedicated ML-KEM-768 + X25519 encryption-only subkey (the combination of RFC 9980 Appendix A.5).Generate a post-quantum OpenPGP key with hash-based signatures at the higher security level: an SLH-DSA-SHAKE-256s certify-only primary key, a dedicated SLH-DSA-SHAKE-256s sign-only subkey and a dedicated ML-KEM-1024 + X448 encryption-only subkey (the combination of RFC 9980 Appendix A.7).Generate an OpenPGP key with a certification-capable primary key.withPrimaryKey(KeyPairGeneratorCallback keyGenCallback) Generate an OpenPGP key with a certification-capable primary key.withPrimaryKey(KeyPairGeneratorCallback keyGenCallback, SignatureParameters.Callback preferenceSignatureCallback) Generate an OpenPGP key with a certification-capable primary key.Methods inherited from class AbstractOpenPGPKeySignatureGenerator
setDefaultAeadAlgorithmPreferences, setDefaultCompressionAlgorithmPreferences, setDefaultFeatures, setDefaultHashAlgorithmPreferences, setDefaultSymmetricKeyPreferences, setDirectKeySignatureSubpackets, setEncryptionSubkeySubpackets, setSigningSubkeySubpackets
-
Constructor Details
-
OpenPGPKeyGenerator
public OpenPGPKeyGenerator(OpenPGPImplementation implementation, boolean aead, Date creationTime) throws PGPException - Throws:
PGPException
-
OpenPGPKeyGenerator
public OpenPGPKeyGenerator(OpenPGPImplementation implementationProvider, int version, boolean aead, Date creationTime) throws PGPException - Throws:
PGPException
-
OpenPGPKeyGenerator
public OpenPGPKeyGenerator(OpenPGPImplementation implementationProvider, int keyVersion, PGPKeyPairGeneratorProvider kpGenProvider, PGPDigestCalculatorProvider digestCalculatorProvider, PBESecretKeyEncryptorFactory keyEncryptionBuilderProvider, KeyFingerPrintCalculator keyFingerPrintCalculator, Date creationTime) Generate a new OpenPGP key generator for v6 keys.- Parameters:
kpGenProvider- key pair generator providerdigestCalculatorProvider- digest calculator providerkeyEncryptionBuilderProvider- secret key encryption builder provider (AEAD)keyFingerPrintCalculator- calculator for key fingerprintscreationTime- key creation time
-
-
Method Details
-
classicKey
Generate an OpenPGP key consisting of a certify-only primary key, a dedicated signing-subkey and dedicated encryption-subkey. The key will optionally carry the provided user-id. SeePGPKeyPairGenerator.generatePrimaryKey()for the primary key type,PGPKeyPairGenerator.generateSigningSubkey()for the signing-subkey type andPGPKeyPairGenerator.generateEncryptionSubkey()for the encryption-subkey key type.- Parameters:
userId- nullable user id- Returns:
- OpenPGP key
- Throws:
PGPException- if the key cannot be prepared
-
ed25519x25519Key
Generate an OpenPGP key consisting of an Ed25519 certify-only primary key, a dedicated Ed25519 sign-only subkey and dedicated X25519 encryption-only subkey. The key will optionally carry the provided user-id.- Parameters:
userId- nullable user id- Returns:
- OpenPGP key
- Throws:
PGPException- if the key cannot be generated
-
ed448x448Key
Generate an OpenPGP key consisting of an Ed448 certify-only primary key, a dedicated Ed448 sign-only subkey and dedicated X448 encryption-only subkey. The key will optionally carry the provided user-id.- Parameters:
userId- nullable user id- Returns:
- OpenPGP key
- Throws:
PGPException- if the key cannot be generated
-
mlDsa65Ed25519MlKem768X25519Key
public OpenPGPKeyGenerator.WithPrimaryKey mlDsa65Ed25519MlKem768X25519Key(String userId) throws PGPException Generate a post-quantum/traditional OpenPGP key as RFC 9980 specifies it: an ML-DSA-65 + Ed25519 certify-only primary key, a dedicated ML-DSA-65 + Ed25519 sign-only subkey and a dedicated ML-KEM-768 + X25519 encryption-only subkey - the two algorithms a conformant implementation MUST support. The key will optionally carry the provided user-id. Only version 6 keys may use these algorithms.- Parameters:
userId- nullable user id- Returns:
- OpenPGP key
- Throws:
PGPException- if the key cannot be generated, in particular for a key version other than 6- See Also:
-
mlDsa87Ed448MlKem1024X448Key
public OpenPGPKeyGenerator.WithPrimaryKey mlDsa87Ed448MlKem1024X448Key(String userId) throws PGPException Generate a post-quantum/traditional OpenPGP key at the higher RFC 9980 security level: an ML-DSA-87 + Ed448 certify-only primary key, a dedicated ML-DSA-87 + Ed448 sign-only subkey and a dedicated ML-KEM-1024 + X448 encryption-only subkey. The key will optionally carry the provided user-id. Only version 6 keys may use these algorithms.- Parameters:
userId- nullable user id- Returns:
- OpenPGP key
- Throws:
PGPException- if the key cannot be generated, in particular for a key version other than 6- See Also:
-
slhDsaShake128sMlKem768X25519Key
public OpenPGPKeyGenerator.WithPrimaryKey slhDsaShake128sMlKem768X25519Key(String userId) throws PGPException Generate a post-quantum OpenPGP key with hash-based signatures: an SLH-DSA-SHAKE-128s certify-only primary key, a dedicated SLH-DSA-SHAKE-128s sign-only subkey and a dedicated ML-KEM-768 + X25519 encryption-only subkey (the combination of RFC 9980 Appendix A.5). SLH-DSA signing is slow and its signatures are large; see RFC 9980 sec. 10.1 before choosing it. The key will optionally carry the provided user-id. Only version 6 keys may use these algorithms.- Parameters:
userId- nullable user id- Returns:
- OpenPGP key
- Throws:
PGPException- if the key cannot be generated, in particular for a key version other than 6- See Also:
-
slhDsaShake128fMlKem768X25519Key
public OpenPGPKeyGenerator.WithPrimaryKey slhDsaShake128fMlKem768X25519Key(String userId) throws PGPException Generate a post-quantum OpenPGP key with fast hash-based signatures: an SLH-DSA-SHAKE-128f certify-only primary key, a dedicated SLH-DSA-SHAKE-128f sign-only subkey and a dedicated ML-KEM-768 + X25519 encryption-only subkey (the combination of RFC 9980 Appendix A.6). The "f" parameter set signs faster than "s" at the price of a larger signature; see RFC 9980 sec. 10.1. The key will optionally carry the provided user-id. Only version 6 keys may use these algorithms.- Parameters:
userId- nullable user id- Returns:
- OpenPGP key
- Throws:
PGPException- if the key cannot be generated, in particular for a key version other than 6- See Also:
-
slhDsaShake256sMlKem1024X448Key
public OpenPGPKeyGenerator.WithPrimaryKey slhDsaShake256sMlKem1024X448Key(String userId) throws PGPException Generate a post-quantum OpenPGP key with hash-based signatures at the higher security level: an SLH-DSA-SHAKE-256s certify-only primary key, a dedicated SLH-DSA-SHAKE-256s sign-only subkey and a dedicated ML-KEM-1024 + X448 encryption-only subkey (the combination of RFC 9980 Appendix A.7). The key will optionally carry the provided user-id. Only version 6 keys may use these algorithms.- Parameters:
userId- nullable user id- Returns:
- OpenPGP key
- Throws:
PGPException- if the key cannot be generated, in particular for a key version other than 6- See Also:
-
signOnlyKey
Generate a sign-only OpenPGP key. The key consists of a single, user-id-less primary key, which is capable of signing and certifying. SeePGPKeyPairGenerator.generatePrimaryKey()for the key type.- Returns:
- sign-only (+certify) OpenPGP key
- Throws:
PGPException- if the key cannot be generated
-
singletonRSAKey
public OpenPGPKeyGenerator.WithPrimaryKey singletonRSAKey(int bitStrength, String userId) throws PGPException Generate an OpenPGP key based on a single, multipurpose RSA key of the given strength. The key will carry a direct-key signature containing default preferences and flags. If the passed in userId is non-null, it will be added to the key.- Parameters:
bitStrength- strength of the RSA key in bits (recommended values: 3072 and above).userId- optional user-id- Returns:
- builder
- Throws:
PGPException- if the key cannot be generated.
-
compositeRSAKey
public OpenPGPKeyGenerator.WithPrimaryKey compositeRSAKey(int bitStrength, String userId) throws PGPException Generate an OpenPGP key composed of 3 individual component keys based on RSA of the given strength in bits. The primary key will be used to certify third-party keys. A subkey is used for signing and a third subkey is used for encryption of messages both for storage and communications. The primary key will carry a direct-key signature containing default preferences and flags. The subkeys will be bound with subkey binding signatures. If the passed in userId is non-null, it will be added to the key.- Parameters:
bitStrength- strength of the keys in bits (recommended values: 3072 and above)userId- optional user-id- Returns:
- builder
- Throws:
PGPException- if the key cannot be generated
-
withPrimaryKey
Generate an OpenPGP key with a certification-capable primary key. SeePGPKeyPairGenerator.generatePrimaryKey()for the primary key type- Returns:
- builder
- Throws:
PGPException- if the key cannot be generated
-
withPrimaryKey
public OpenPGPKeyGenerator.WithPrimaryKey withPrimaryKey(KeyPairGeneratorCallback keyGenCallback) throws PGPException Generate an OpenPGP key with a certification-capable primary key. The primary key type can be decided using theKeyPairGeneratorCallback.- Parameters:
keyGenCallback- callback to decide the key type- Returns:
- builder
- Throws:
PGPException- if the key cannot be generated
-
withPrimaryKey
public OpenPGPKeyGenerator.WithPrimaryKey withPrimaryKey(KeyPairGeneratorCallback keyGenCallback, SignatureParameters.Callback preferenceSignatureCallback) throws PGPException Generate an OpenPGP key with a certification-capable primary key. The primary key type can be decided using theKeyPairGeneratorCallback. TheSignatureParameters.Callbackcan be used to modify the preferences in the direct-key self signature. If the callback itself is null, the generator will create a default direct-key signature. If the result ofSignatureParameters.Callback.apply(SignatureParameters)is null, no direct-key signature will be generated for the key.- Parameters:
keyGenCallback- callback to decide the key typepreferenceSignatureCallback- callback to modify the direct-key signature- Returns:
- builder
- Throws:
PGPException- if the key cannot be generated
-