HPKE (Bouncy Castle Library 1.85 API Specification)
Date: 2026-07-12

org.bouncycastle.crypto.hpke

## Class HPKE

- java.lang.Object
- - org.bouncycastle.crypto.hpke.HPKE

-     public class HPKE
      extends java.lang.Object

  Hybrid Public Key Encryption (HPKE) per RFC 9180.

  Top-level facade. A single instance pins a (mode, KEM, KDF, AEAD) suite via the constructor and exposes:

  - `setupBaseS` / `setupBaseR` / `SetupPSKS` / `setupPSKR` / `setupAuthS` / `setupAuthR` / `setupAuthPSKS` / `setupAuthPSKR` — return a stateful `HPKEContext` (recipient) or `HPKEContextWithEncapsulation` (sender, also carries the `enc` octet string).
  - `seal(pkR, info, aad, pt)` / `open(enc, skR, info, aad, ct)` — single-message conveniences that do setup + seal/open in one call.
  - `sendExport` / `receiveExport` — export-only operation (no AEAD seal); pair with the `aead_EXPORT_ONLY` sentinel suite when seal/open aren't needed.
  - `serializePublicKey(org.bouncycastle.crypto.params.AsymmetricKeyParameter)` / `deserializePublicKey(byte[])` / `serializePrivateKey(org.bouncycastle.crypto.params.AsymmetricKeyParameter)` — KEM-aware key encoding helpers.
  The package package overview covers the typical sender/receiver caller flow and the supported algorithm matrix.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static short` | `aead_AES_GCM128`
    `static short` | `aead_AES_GCM256`
    `static short` | `aead_CHACHA20_POLY1305`
    `static short` | `aead_EXPORT_ONLY`
    `static short` | `kdf_HKDF_SHA256`
    `static short` | `kdf_HKDF_SHA384`
    `static short` | `kdf_HKDF_SHA512`
    `static short` | `kem_P256_SHA256`
    `static short` | `kem_P384_SHA348` Deprecated. use kem_P384_SHA384
    `static short` | `kem_P384_SHA384`
    `static short` | `kem_P521_SHA512`
    `static short` | `kem_X25519_SHA256`
    `static short` | `kem_X448_SHA512`
    `static byte` | `mode_auth`
    `static byte` | `mode_auth_psk`
    `static byte` | `mode_base`
    `static byte` | `mode_psk`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `HPKE(byte mode, short kemId, short kdfId, short aeadId)` Hybrid Public Key Encryption as described in RFC9180.
    `HPKE(byte mode, short kemId, short kdfId, short aeadId, KEM kem, int encSize)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `AsymmetricCipherKeyPair` | `deriveKeyPair(byte[] ikm)`
    `AsymmetricCipherKeyPair` | `deserializePrivateKey(byte[] skEncoded, byte[] pkEncoded)`
    `AsymmetricKeyParameter` | `deserializePublicKey(byte[] pkEncoded)`
    `AsymmetricCipherKeyPair` | `generatePrivateKey()`
    `short` | `getAeadId()`
    `int` | `getEncSize()`
    `byte[]` | `open(byte[] enc, AsymmetricCipherKeyPair skR, byte[] info, byte[] aad, byte[] ct, byte[] psk, byte[] pskId, AsymmetricKeyParameter pkS)`
    `byte[]` | `receiveExport(byte[] enc, AsymmetricCipherKeyPair skR, byte[] info, byte[] exporterContext, int L, byte[] psk, byte[] pskId, AsymmetricKeyParameter pkS)`
    `byte[][]` | `seal(AsymmetricKeyParameter pkR, byte[] info, byte[] aad, byte[] pt, byte[] psk, byte[] pskId, AsymmetricCipherKeyPair skS)`
    `byte[][]` | `sendExport(AsymmetricKeyParameter pkR, byte[] info, byte[] exporterContext, int L, byte[] psk, byte[] pskId, AsymmetricCipherKeyPair skS)`
    `byte[]` | `serializePrivateKey(AsymmetricKeyParameter sk)`
    `byte[]` | `serializePublicKey(AsymmetricKeyParameter pk)`
    `HPKEContext` | `setupAuthPSKR(byte[] enc, AsymmetricCipherKeyPair skR, byte[] info, byte[] psk, byte[] psk_id, AsymmetricKeyParameter pkS)`
    `HPKEContextWithEncapsulation` | `setupAuthPSKS(AsymmetricKeyParameter pkR, byte[] info, byte[] psk, byte[] psk_id, AsymmetricCipherKeyPair skS)`
    `HPKEContext` | `setupAuthR(byte[] enc, AsymmetricCipherKeyPair skR, byte[] info, AsymmetricKeyParameter pkS)`
    `HPKEContextWithEncapsulation` | `setupAuthS(AsymmetricKeyParameter pkR, byte[] info, AsymmetricCipherKeyPair skS)`
    `HPKEContext` | `setupBaseR(byte[] enc, AsymmetricCipherKeyPair skR, byte[] info)`
    `HPKEContextWithEncapsulation` | `setupBaseS(AsymmetricKeyParameter pkR, byte[] info)`
    `HPKEContextWithEncapsulation` | `setupBaseS(AsymmetricKeyParameter pkR, byte[] info, AsymmetricCipherKeyPair kpE)`
    `HPKEContext` | `setupPSKR(byte[] enc, AsymmetricCipherKeyPair skR, byte[] info, byte[] psk, byte[] psk_id)`
    `HPKEContextWithEncapsulation` | `SetupPSKS(AsymmetricKeyParameter pkR, byte[] info, byte[] psk, byte[] psk_id)`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### mode_base

          public static final byte mode_base

      See Also:
        Constant Field Values

    - #### mode_psk

          public static final byte mode_psk

      See Also:
        Constant Field Values

    - #### mode_auth

          public static final byte mode_auth

      See Also:
        Constant Field Values

    - #### mode_auth_psk

          public static final byte mode_auth_psk

      See Also:
        Constant Field Values

    - #### kem_P256_SHA256

          public static final short kem_P256_SHA256

      See Also:
        Constant Field Values

    - #### kem_P384_SHA348

          public static final short kem_P384_SHA348

      Deprecated. use kem_P384_SHA384
      See Also:
        Constant Field Values

    - #### kem_P384_SHA384

          public static final short kem_P384_SHA384

      See Also:
        Constant Field Values

    - #### kem_P521_SHA512

          public static final short kem_P521_SHA512

      See Also:
        Constant Field Values

    - #### kem_X25519_SHA256

          public static final short kem_X25519_SHA256

      See Also:
        Constant Field Values

    - #### kem_X448_SHA512

          public static final short kem_X448_SHA512

      See Also:
        Constant Field Values

    - #### kdf_HKDF_SHA256

          public static final short kdf_HKDF_SHA256

      See Also:
        Constant Field Values

    - #### kdf_HKDF_SHA384

          public static final short kdf_HKDF_SHA384

      See Also:
        Constant Field Values

    - #### kdf_HKDF_SHA512

          public static final short kdf_HKDF_SHA512

      See Also:
        Constant Field Values

    - #### aead_AES_GCM128

          public static final short aead_AES_GCM128

      See Also:
        Constant Field Values

    - #### aead_AES_GCM256

          public static final short aead_AES_GCM256

      See Also:
        Constant Field Values

    - #### aead_CHACHA20_POLY1305

          public static final short aead_CHACHA20_POLY1305

      See Also:
        Constant Field Values

    - #### aead_EXPORT_ONLY

          public static final short aead_EXPORT_ONLY

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### HPKE

          public HPKE(byte mode,
                      short kemId,
                      short kdfId,
                      short aeadId)

      Hybrid Public Key Encryption as described in RFC9180.
      See Also:
        RFC9180 An implementation of the Hybrid Public Key Encryption.

    - #### HPKE

          public HPKE(byte mode,
                      short kemId,
                      short kdfId,
                      short aeadId,
                      KEM kem,
                      int encSize)

  - ### Method Detail

    - #### getEncSize

          public int getEncSize()

    - #### getAeadId

          public short getAeadId()

    - #### generatePrivateKey

          public AsymmetricCipherKeyPair generatePrivateKey()

    - #### serializePublicKey

          public byte[] serializePublicKey(AsymmetricKeyParameter pk)

    - #### serializePrivateKey

          public byte[] serializePrivateKey(AsymmetricKeyParameter sk)

    - #### deserializePublicKey

          public AsymmetricKeyParameter deserializePublicKey(byte[] pkEncoded)

    - #### deserializePrivateKey

          public AsymmetricCipherKeyPair deserializePrivateKey(byte[] skEncoded,
                                                               byte[] pkEncoded)

    - #### deriveKeyPair

          public AsymmetricCipherKeyPair deriveKeyPair(byte[] ikm)

    - #### sendExport

          public byte[][] sendExport(AsymmetricKeyParameter pkR,
                                     byte[] info,
                                     byte[] exporterContext,
                                     int L,
                                     byte[] psk,
                                     byte[] pskId,
                                     AsymmetricCipherKeyPair skS)

    - #### receiveExport

          public byte[] receiveExport(byte[] enc,
                                      AsymmetricCipherKeyPair skR,
                                      byte[] info,
                                      byte[] exporterContext,
                                      int L,
                                      byte[] psk,
                                      byte[] pskId,
                                      AsymmetricKeyParameter pkS)

    - #### seal

          public byte[][] seal(AsymmetricKeyParameter pkR,
                               byte[] info,
                               byte[] aad,
                               byte[] pt,
                               byte[] psk,
                               byte[] pskId,
                               AsymmetricCipherKeyPair skS)
                        throws InvalidCipherTextException

      Throws:
        `InvalidCipherTextException`

    - #### open

          public byte[] open(byte[] enc,
                             AsymmetricCipherKeyPair skR,
                             byte[] info,
                             byte[] aad,
                             byte[] ct,
                             byte[] psk,
                             byte[] pskId,
                             AsymmetricKeyParameter pkS)
                      throws InvalidCipherTextException

      Throws:
        `InvalidCipherTextException`

    - #### setupBaseS

          public HPKEContextWithEncapsulation setupBaseS(AsymmetricKeyParameter pkR,
                                                         byte[] info)

    - #### setupBaseS

          public HPKEContextWithEncapsulation setupBaseS(AsymmetricKeyParameter pkR,
                                                         byte[] info,
                                                         AsymmetricCipherKeyPair kpE)

    - #### setupBaseR

          public HPKEContext setupBaseR(byte[] enc,
                                        AsymmetricCipherKeyPair skR,
                                        byte[] info)

    - #### SetupPSKS

          public HPKEContextWithEncapsulation SetupPSKS(AsymmetricKeyParameter pkR,
                                                        byte[] info,
                                                        byte[] psk,
                                                        byte[] psk_id)

    - #### setupPSKR

          public HPKEContext setupPSKR(byte[] enc,
                                       AsymmetricCipherKeyPair skR,
                                       byte[] info,
                                       byte[] psk,
                                       byte[] psk_id)

    - #### setupAuthS

          public HPKEContextWithEncapsulation setupAuthS(AsymmetricKeyParameter pkR,
                                                         byte[] info,
                                                         AsymmetricCipherKeyPair skS)

    - #### setupAuthR

          public HPKEContext setupAuthR(byte[] enc,
                                        AsymmetricCipherKeyPair skR,
                                        byte[] info,
                                        AsymmetricKeyParameter pkS)

    - #### setupAuthPSKS

          public HPKEContextWithEncapsulation setupAuthPSKS(AsymmetricKeyParameter pkR,
                                                            byte[] info,
                                                            byte[] psk,
                                                            byte[] psk_id,
                                                            AsymmetricCipherKeyPair skS)

    - #### setupAuthPSKR

          public HPKEContext setupAuthPSKR(byte[] enc,
                                           AsymmetricCipherKeyPair skR,
                                           byte[] info,
                                           byte[] psk,
                                           byte[] psk_id,
                                           AsymmetricKeyParameter pkS)