Class BcPublicKeyCryptoCallback

java.lang.Object
org.bouncycastle.openpgp.operator.bc.BcPublicKeyCryptoCallback

public abstract class BcPublicKeyCryptoCallback extends Object
Callback isolating the raw public-key operations performed while recovering an OpenPGP session key.

BcPublicKeyDataDecryptorFactory performs all packet parsing, length checking and KDF/key-unwrap work itself and delegates only the private-key operation - an RSA or ElGamal decryption, or an ECDH / X25519 / X448 agreement - to an instance of this class. A subclass may therefore route that one operation to a hardware device (a smart card or HSM) without reimplementing any of the session-key recovery logic. See org.bouncycastle.openpgp.api.operator.bc.BcExternalPublicKeyDataDecryptorFactory for the externally-backed-key base class built on this seam.

This is the lightweight (.bc) binding: keys are passed as AsymmetricKeyParameter. It deliberately lives in the .bc subpackage rather than alongside AbstractPublicKeyDataDecryptorFactory, because the top-level operator package is JCA-free and lightweight-crypto-free.

  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    abstract byte[]
    decryptECDH(ECDHPublicBCPGKey pubKey, byte[] ephemeralKeyBytes, org.bouncycastle.crypto.params.AsymmetricKeyParameter privKey)
    Perform an ECDH agreement to calculate a shared secret.
    abstract byte[]
    decryptElGamal(int keyAlgorithm, byte[][] secKeyData, org.bouncycastle.crypto.params.AsymmetricKeyParameter privKey)
    Perform ElGamal decryption of an encrypted session key.
    abstract byte[]
    decryptRSA(int keyAlgorithm, byte[] pEnc, org.bouncycastle.crypto.params.AsymmetricKeyParameter privKey)
    Perform RSA decryption of an encrypted session key.
    abstract byte[]
    decryptX25519(org.bouncycastle.crypto.params.AsymmetricKeyParameter privKey, byte[] ephemeralKey)
    Perform an X25519 agreement to calculate a shared secret.
    abstract byte[]
    decryptX448(org.bouncycastle.crypto.params.AsymmetricKeyParameter privKey, byte[] ephemeralKey)
    Perform an X448 agreement to calculate a shared secret.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • BcPublicKeyCryptoCallback

      public BcPublicKeyCryptoCallback()
  • Method Details

    • decryptRSA

      public abstract byte[] decryptRSA(int keyAlgorithm, byte[] pEnc, org.bouncycastle.crypto.params.AsymmetricKeyParameter privKey) throws PGPException, org.bouncycastle.crypto.InvalidCipherTextException
      Perform RSA decryption of an encrypted session key.
      Parameters:
      keyAlgorithm - public key algorithm
      pEnc - encrypted session key
      privKey - RSA private key
      Returns:
      decrypted session key
      Throws:
      PGPException - if the message cannot be decrypted
      org.bouncycastle.crypto.InvalidCipherTextException - if the ciphertext is invalid
    • decryptElGamal

      public abstract byte[] decryptElGamal(int keyAlgorithm, byte[][] secKeyData, org.bouncycastle.crypto.params.AsymmetricKeyParameter privKey) throws org.bouncycastle.crypto.InvalidCipherTextException, PGPException
      Perform ElGamal decryption of an encrypted session key.
      Parameters:
      keyAlgorithm - public key algorithm
      secKeyData - encrypted session key data
      privKey - ElGamal private key
      Returns:
      decrypted session key
      Throws:
      org.bouncycastle.crypto.InvalidCipherTextException - if the ciphertext is invalid
      PGPException - if the message cannot be decrypted
    • decryptECDH

      public abstract byte[] decryptECDH(ECDHPublicBCPGKey pubKey, byte[] ephemeralKeyBytes, org.bouncycastle.crypto.params.AsymmetricKeyParameter privKey) throws PGPException
      Perform an ECDH agreement to calculate a shared secret.
      Parameters:
      pubKey - our ECDH public key
      ephemeralKeyBytes - encoded ephemeral public key
      privKey - private ECDH key
      Returns:
      shared secret
      Throws:
      PGPException - if the message cannot be decrypted
    • decryptX25519

      public abstract byte[] decryptX25519(org.bouncycastle.crypto.params.AsymmetricKeyParameter privKey, byte[] ephemeralKey) throws PGPException
      Perform an X25519 agreement to calculate a shared secret.
      Parameters:
      privKey - private X25519 key
      ephemeralKey - encoded ephemeral X25519 public key
      Returns:
      shared secret
      Throws:
      PGPException - if the message cannot be decrypted
    • decryptX448

      public abstract byte[] decryptX448(org.bouncycastle.crypto.params.AsymmetricKeyParameter privKey, byte[] ephemeralKey) throws PGPException
      Perform an X448 agreement to calculate a shared secret.
      Parameters:
      privKey - private X448 key
      ephemeralKey - encoded ephemeral X448 public key
      Returns:
      shared secret
      Throws:
      PGPException - if the message cannot be decrypted