Class OpenPGPKeyGenerator

Direct Known Subclasses:
BcOpenPGPKeyGenerator, JcaOpenPGPKeyGenerator

public class OpenPGPKeyGenerator extends AbstractOpenPGPKeySignatureGenerator
High-level generator class for OpenPGP v6 keys.
  • Constructor Details

  • Method Details

    • classicKey

      public OpenPGPKeyGenerator.WithPrimaryKey classicKey(String userId) throws PGPException
      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. See PGPKeyPairGenerator.generatePrimaryKey() for the primary key type, PGPKeyPairGenerator.generateSigningSubkey() for the signing-subkey type and PGPKeyPairGenerator.generateEncryptionSubkey() for the encryption-subkey key type.
      Parameters:
      userId - nullable user id
      Returns:
      OpenPGP key
      Throws:
      PGPException - if the key cannot be prepared
    • ed25519x25519Key

      public OpenPGPKeyGenerator.WithPrimaryKey ed25519x25519Key(String userId) throws PGPException
      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

      public OpenPGPKeyGenerator.WithPrimaryKey ed448x448Key(String userId) throws PGPException
      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

      public OpenPGPKeyGenerator.WithPrimaryKey signOnlyKey() throws PGPException
      Generate a sign-only OpenPGP key. The key consists of a single, user-id-less primary key, which is capable of signing and certifying. See PGPKeyPairGenerator.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

      public OpenPGPKeyGenerator.WithPrimaryKey withPrimaryKey() throws PGPException
      Generate an OpenPGP key with a certification-capable primary key. See PGPKeyPairGenerator.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 the KeyPairGeneratorCallback.
      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 the KeyPairGeneratorCallback. The SignatureParameters.Callback can 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 of SignatureParameters.Callback.apply(SignatureParameters) is null, no direct-key signature will be generated for the key.
      Parameters:
      keyGenCallback - callback to decide the key type
      preferenceSignatureCallback - callback to modify the direct-key signature
      Returns:
      builder
      Throws:
      PGPException - if the key cannot be generated