Class OpenPGPKeyGenerator.WithPrimaryKey
java.lang.Object
org.bouncycastle.openpgp.api.OpenPGPKeyGenerator.WithPrimaryKey
- Enclosing class:
OpenPGPKeyGenerator
Intermediate builder class.
Constructs an OpenPGP key from a specified primary key.
-
Method Summary
Modifier and TypeMethodDescriptionAdd an encryption-capable subkey to the OpenPGP key.addEncryptionSubkey(KeyPairGeneratorCallback keyGenCallback) Add an encryption-capable subkey to the OpenPGP key.addEncryptionSubkey(KeyPairGeneratorCallback generatorCallback, SignatureParameters.Callback bindingSubpacketsCallback) Add an encryption-capable subkey to the OpenPGP key.addEncryptionSubkey(PGPKeyPair encryptionSubkey, SignatureParameters.Callback bindingSubpacketsCallback) Add an encryption-capable subkey to the OpenPGP key.Add a signing-capable subkey to the OpenPGP key.addSigningSubkey(KeyPairGeneratorCallback keyGenCallback) Add a signing-capable subkey to the OpenPGP key.addSigningSubkey(KeyPairGeneratorCallback keyGenCallback, SignatureParameters.Callback bindingSignatureCallback, SignatureParameters.Callback backSignatureCallback) Add a signing-capable subkey to the OpenPGP key.addSigningSubkey(PGPKeyPair signingSubkey, SignatureParameters.Callback bindingSignatureCallback, SignatureParameters.Callback backSignatureCallback) Add a signing-capable subkey to the OpenPGP key.Attach a User-ID with a positive certification to the key.addUserId(String userId, SignatureParameters.Callback signatureParameters) Attach a User-ID with a positive certification to the key.build()Build theOpenPGP keywithout protecting the secret keys.build(char[] passphrase) Build theOpenPGP keyusing a single passphrase used to protect all subkeys.protected voidsanitizeKeyEncryptor(PBESecretKeyEncryptor keyEncryptor)
-
Method Details
-
addUserId
Attach a User-ID with a positive certification to the key.- Parameters:
userId- user-id- Returns:
- builder
- Throws:
PGPException- if the user-id cannot be added
-
addUserId
public OpenPGPKeyGenerator.WithPrimaryKey addUserId(String userId, SignatureParameters.Callback signatureParameters) throws PGPException Attach a User-ID with a positive certification to the key. The subpackets of the user-id certification can be modified using the userIdSubpackets callback.- Parameters:
userId- user-idsignatureParameters- signature parameters- Returns:
- builder
- Throws:
PGPException- if the user-id cannot be added
-
addEncryptionSubkey
Add an encryption-capable subkey to the OpenPGP key. SeePGPKeyPairGenerator.generateEncryptionSubkey()for the key type.- Returns:
- builder
- Throws:
PGPException- if the key cannot be generated
-
addEncryptionSubkey
public OpenPGPKeyGenerator.WithPrimaryKey addEncryptionSubkey(KeyPairGeneratorCallback keyGenCallback) throws PGPException Add an encryption-capable subkey to the OpenPGP key. The type of the subkey can be decided by implementing theKeyPairGeneratorCallback.- Parameters:
keyGenCallback- callback to decide the encryption subkey type- Returns:
- builder
- Throws:
PGPException- if the key cannot be generated
-
addEncryptionSubkey
public OpenPGPKeyGenerator.WithPrimaryKey addEncryptionSubkey(KeyPairGeneratorCallback generatorCallback, SignatureParameters.Callback bindingSubpacketsCallback) throws PGPException Add an encryption-capable subkey to the OpenPGP key. The type of the subkey can be decided by implementing theKeyPairGeneratorCallback. The binding signature can be modified by implementing theSignatureSubpacketsFunction.- Parameters:
generatorCallback- callback to specify the encryption key type.bindingSubpacketsCallback- nullable callback to modify the binding signature subpackets- Returns:
- builder
- Throws:
PGPException- if the key cannot be generated
-
addEncryptionSubkey
public OpenPGPKeyGenerator.WithPrimaryKey addEncryptionSubkey(PGPKeyPair encryptionSubkey, SignatureParameters.Callback bindingSubpacketsCallback) throws PGPException Add an encryption-capable subkey to the OpenPGP key. IMPORTANT: The custom key encryptor will only be used, if in the final step the key is retrieved usingbuild(). If insteadbuild(char[])is used, the key-specific encryptor is overwritten with an encryptor built from the argument passed intobuild(char[]).- Parameters:
encryptionSubkey- encryption subkeybindingSubpacketsCallback- nullable callback to modify the subkey binding signature subpackets- Returns:
- builder
- Throws:
PGPException- if the key cannot be generated
-
addSigningSubkey
Add a signing-capable subkey to the OpenPGP key. The binding signature will contain a primary-key back-signature. SeePGPKeyPairGenerator.generateSigningSubkey()for the key type.- Returns:
- builder
- Throws:
PGPException- if the key cannot be generated
-
addSigningSubkey
public OpenPGPKeyGenerator.WithPrimaryKey addSigningSubkey(KeyPairGeneratorCallback keyGenCallback) throws PGPException Add a signing-capable subkey to the OpenPGP key. The signing-key type can be specified by overriding theKeyPairGeneratorCallback. The binding signature will contain a primary-key back-signature. IMPORTANT: The custom subkey passphrase will only be used, if in the final step the key is retrieved usingbuild(). If insteadbuild(char[])is used, the key-specific passphrase is overwritten with the argument passed intobuild(char[]).- Parameters:
keyGenCallback- callback to specify the signing-key type- Returns:
- builder
- Throws:
PGPException- if the key cannot be generated
-
addSigningSubkey
public OpenPGPKeyGenerator.WithPrimaryKey addSigningSubkey(KeyPairGeneratorCallback keyGenCallback, SignatureParameters.Callback bindingSignatureCallback, SignatureParameters.Callback backSignatureCallback) throws PGPException Add a signing-capable subkey to the OpenPGP key. The signing-key type can be specified by overriding theKeyPairGeneratorCallback. The binding signature will contain a primary-key back-signature. The contents of the binding signature(s) can be modified by overriding the respectiveSignatureSubpacketsFunctioninstances. IMPORTANT: The custom subkey passphrase will only be used, if in the final step the key is retrieved usingbuild(). If insteadbuild(char[])is used, the key-specific passphrase is overwritten with the argument passed intobuild(char[]).- Parameters:
keyGenCallback- callback to specify the signing-key typebindingSignatureCallback- callback to modify the contents of the signing subkey binding signaturebackSignatureCallback- callback to modify the contents of the embedded primary key binding signature- Returns:
- builder
- Throws:
PGPException- if the key cannot be generated
-
addSigningSubkey
public OpenPGPKeyGenerator.WithPrimaryKey addSigningSubkey(PGPKeyPair signingSubkey, SignatureParameters.Callback bindingSignatureCallback, SignatureParameters.Callback backSignatureCallback) throws PGPException Add a signing-capable subkey to the OpenPGP key. The signing-key type can be specified by overriding theKeyPairGeneratorCallback. The binding signature will contain a primary-key back-signature. The contents of the binding signature(s) can be modified by overriding the respectiveSignatureSubpacketsFunctioninstances. IMPORTANT: The custom key encryptor will only be used, if in the final step the key is retrieved usingbuild(). If insteadbuild(char[])is used, the key-specific encryptor is overwritten with an encryptor built from the argument passed intobuild(char[]).- Parameters:
signingSubkey- signing subkeybindingSignatureCallback- callback to modify the contents of the signing subkey binding signaturebackSignatureCallback- callback to modify the contents of the embedded primary key binding signature- Returns:
- builder
- Throws:
PGPException- if the key cannot be generated
-
build
Build theOpenPGP keywithout protecting the secret keys.- Returns:
- OpenPGP key
- Throws:
PGPException- if the key cannot be generated
-
build
Build theOpenPGP keyusing a single passphrase used to protect all subkeys. The passphrase will override whichever key protectors were specified in previous builder steps.The array passed in is zeroized once the key has been generated, so a caller that needs to keep the passphrase - to generate a second key with it, say - must pass a clone. This is the one place in the API that clears a caller's array; a
KeyPassphraseProviderkeeps ownership of what it hands out (seeKeyPassphraseProvider.getKeyPassword(OpenPGPKey.OpenPGPSecretKey)).- Parameters:
passphrase- nullable passphrase, zeroized before this method returns- Returns:
- OpenPGP key
- Throws:
PGPException- if the key cannot be generated
-
sanitizeKeyEncryptor
-