Top Fields Constructors Methods
org.bouncycastle.openpgp.operator

public abstract Class PGPKeyPairGenerator

extends Object
Class Inheritance
Known Direct Subclasses
org.bouncycastle.openpgp.operator.bc.BcPGPKeyPairGeneratorProvider.BcPGPKeyPairGenerator, org.bouncycastle.openpgp.operator.jcajce.JcaPGPKeyPairGeneratorProvider.JcaPGPKeyPairGenerator
Imports
org.bouncycastle.bcpg.PublicKeyAlgorithmTags, org.bouncycastle.openpgp.PGPException, .PGPKeyPair, java.math.BigInteger, java.security.SecureRandom, java.util.Date

Field Summary

Modifier and TypeField and Description
protected final Date
protected final KeyFingerPrintCalculator
protected SecureRandom
protected final int

Constructor Summary

AccessConstructor and Description
public
PGPKeyPairGenerator(int version, Date
key creation time
creationTime
,
SecureRandom
secure random number generator
random
,
KeyFingerPrintCalculator fingerPrintCalculator)

Create an instance of the key pair generator.

Method Summary

Modifier and TypeMethod and Description
public abstract PGPKeyPair

Returns:

Ed25519 key pair
generateEd25519KeyPair
()

Generate an elliptic curve signing key over the twisted Edwards curve25519.

public abstract PGPKeyPair

Returns:

Ed448 signing key pair
generateEd448KeyPair
()

Generate an elliptic curve signing key over the twisted Edwards curve448.

public PGPKeyPair

Returns:

encryption subkey pair
generateEncryptionSubkey
()

Generate an encryption subkey.

public abstract PGPKeyPair

Returns:

legacy Ed25519 key pair
generateLegacyEd25519KeyPair
()

Generate a legacy elliptic curve signing key pair over the twisted Edwards curve25519.

public abstract PGPKeyPair

Returns:

legacy X25519 key pair
generateLegacyX25519KeyPair
()

Generate a legacy elliptic curve Diffie-Hellman encryption key pair over curve25519.

public PGPKeyPair

Returns:

primary key pair
generatePrimaryKey
()

Generate a primary key.

public PGPKeyPair

Returns:

rsa key pair
generateRsaKeyPair
(int
strength of the key pair in bits
bitStrength
)

Generate a RSA key pair with the given bit-strength.

public abstract PGPKeyPair

Returns:

rsa key pair
generateRsaKeyPair
(BigInteger
RSA exponent
e
exponent
,
int
strength of the key pair in bits
bitStrength
)

Generate a RSA key pair with the given bit-strength over a custom exponent.

public PGPKeyPair

Returns:

signing subkey pair
generateSigningSubkey
()

Generate a signing subkey.

public abstract PGPKeyPair

Returns:

X25519 encryption key pair
generateX25519KeyPair
()

Generate an elliptic curve Diffie-Hellman encryption key over curve25519.

public abstract PGPKeyPair

Returns:

X448 encryption key pair
generateX448KeyPair
()

Generate an elliptic curve Diffie-Hellman encryption key over curve448.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

creationTimeback to summary
protected final Date creationTime
fingerPrintCalculatorback to summary
protected final KeyFingerPrintCalculator fingerPrintCalculator
randomback to summary
protected SecureRandom random
versionback to summary
protected final int version

Constructor Detail

PGPKeyPairGeneratorback to summary
public PGPKeyPairGenerator(int version, Date creationTime, SecureRandom random, KeyFingerPrintCalculator fingerPrintCalculator)

Create an instance of the key pair generator.

Parameters
version:int

public key version (org.bouncycastle.bcpg.PublicKeyPacket#VERSION_4 or org.bouncycastle.bcpg.PublicKeyPacket#VERSION_6).

creationTime:Date

key creation time

random:SecureRandom

secure random number generator

Method Detail

generateEd25519KeyPairback to summary
public abstract PGPKeyPair generateEd25519KeyPair() throws PGPException

Generate an elliptic curve signing key over the twisted Edwards curve25519. The key will use PublicKeyAlgorithmTags#Ed25519 which was introduced with RFC9580. For legacy Ed25519 keys use generateLegacyEd25519KeyPair().

Returns:PGPKeyPair

Ed25519 key pair

Exceptions
PGPException:
if the key pair cannot be generated
See Also
RFC9580 - Public Key Algorithms
generateEd448KeyPairback to summary
public abstract PGPKeyPair generateEd448KeyPair() throws PGPException

Generate an elliptic curve signing key over the twisted Edwards curve448. The key will use PublicKeyAlgorithmTags#Ed448 which was introduced with RFC9580.

Returns:PGPKeyPair

Ed448 signing key pair

Exceptions
PGPException:
if the key pair cannot be generated
See Also
RFC9580 - Public Key Algorithms
generateEncryptionSubkeyback to summary
public PGPKeyPair generateEncryptionSubkey() throws PGPException

Generate an encryption subkey. An encryption subkey MUST use an encryption-capable public key algorithm.

Returns:PGPKeyPair

encryption subkey pair

Exceptions
PGPException:
if the key pair cannot be generated
generateLegacyEd25519KeyPairback to summary
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 use PublicKeyAlgorithmTags#EDDSA_LEGACY as algorithm ID. For OpenPGP v6 (RFC9580) use generateEd25519KeyPair() instead.

Returns:PGPKeyPair

legacy Ed25519 key pair

Exceptions
PGPException:
if the key pair cannot be generated
See Also
Legacy Draft: EdDSA for OpenPGP
generateLegacyX25519KeyPairback to summary
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 use PublicKeyAlgorithmTags#ECDH as algorithm ID. For OpenPGP v6 (RFC9580) use generateX25519KeyPair() instead.

Returns:PGPKeyPair

legacy X25519 key pair

Exceptions
PGPException:
if the key pair cannot be generated
generatePrimaryKeyback to summary
public PGPKeyPair generatePrimaryKey() throws PGPException

Generate a primary key. A primary key MUST use a signing-capable public key algorithm.

Returns:PGPKeyPair

primary key pair

Exceptions
PGPException:
if the key pair cannot be generated
generateRsaKeyPairback to summary
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 exponent

65537
. RSA keys are deprecated for OpenPGP v6.
Parameters
bitStrength:int

strength of the key pair in bits

Returns:PGPKeyPair

rsa key pair

Exceptions
PGPException:
if the key pair cannot be generated
generateRsaKeyPairback to summary
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:BigInteger

RSA exponent

e
bitStrength:int

strength of the key pair in bits

Returns:PGPKeyPair

rsa key pair

Exceptions
PGPException:
if the key pair cannot be generated
generateSigningSubkeyback to summary
public PGPKeyPair generateSigningSubkey() throws PGPException

Generate a signing subkey. A signing subkey MUST use a signing-capable public key algorithm.

Returns:PGPKeyPair

signing subkey pair

Exceptions
PGPException:
if the key pair cannot be generated
generateX25519KeyPairback to summary
public abstract PGPKeyPair generateX25519KeyPair() throws PGPException

Generate an elliptic curve Diffie-Hellman encryption key over curve25519. THe key will use PublicKeyAlgorithmTags#X25519 which was introduced with RFC9580. For legacy X25519 keys use generateLegacyX25519KeyPair() instead.

Returns:PGPKeyPair

X25519 encryption key pair

Exceptions
PGPException:
if the key pair cannot be generated
See Also
RFC9580 - Public Key Algorithms
generateX448KeyPairback to summary
public abstract PGPKeyPair generateX448KeyPair() throws PGPException

Generate an elliptic curve Diffie-Hellman encryption key over curve448. THe key will use PublicKeyAlgorithmTags#X448 which was introduced with RFC9580.

Returns:PGPKeyPair

X448 encryption key pair

Exceptions
PGPException:
if the key pair cannot be generated
See Also
RFC9580 - Public Key Algorithms