Class HPKE
java.lang.Object
org.bouncycastle.crypto.hpke.HPKE
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 statefulHPKEContext(recipient) orHPKEContextWithEncapsulation(sender, also carries theencoctet 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 theaead_EXPORT_ONLYsentinel suite when seal/open aren't needed.serializePublicKey(AsymmetricKeyParameter)/deserializePublicKey(byte[])/serializePrivateKey(AsymmetricKeyParameter)— KEM-aware key encoding helpers.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final shortstatic final shortstatic final shortstatic final shortstatic final shortstatic final shortstatic final shortstatic final shortstatic final shortstatic final shortstatic final shortstatic final shortstatic final shortstatic final shortstatic final shortDeprecated.use kem_P384_SHA384static final shortstatic final shortstatic final shortstatic final shortstatic final shortstatic final bytestatic final bytestatic final bytestatic final byte -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionderiveKeyPair(byte[] ikm) deserializePrivateKey(byte[] skEncoded, byte[] pkEncoded) deserializePublicKey(byte[] pkEncoded) shortintbyte[]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[]byte[]setupAuthPSKR(byte[] enc, AsymmetricCipherKeyPair skR, byte[] info, byte[] psk, byte[] psk_id, AsymmetricKeyParameter pkS) setupAuthPSKS(AsymmetricKeyParameter pkR, byte[] info, byte[] psk, byte[] psk_id, AsymmetricCipherKeyPair skS) setupAuthR(byte[] enc, AsymmetricCipherKeyPair skR, byte[] info, AsymmetricKeyParameter pkS) setupAuthS(AsymmetricKeyParameter pkR, byte[] info, AsymmetricCipherKeyPair skS) setupBaseR(byte[] enc, AsymmetricCipherKeyPair skR, byte[] info) setupBaseS(AsymmetricKeyParameter pkR, byte[] info) setupBaseS(AsymmetricKeyParameter pkR, byte[] info, byte[] ier) setupBaseS(AsymmetricKeyParameter pkR, byte[] info, AsymmetricCipherKeyPair kpE) setupPSKR(byte[] enc, AsymmetricCipherKeyPair skR, byte[] info, byte[] psk, byte[] psk_id) SetupPSKS(AsymmetricKeyParameter pkR, byte[] info, byte[] psk, byte[] psk_id)
-
Field Details
-
mode_base
public static final byte mode_base- See Also:
-
mode_psk
public static final byte mode_psk- See Also:
-
mode_auth
public static final byte mode_auth- See Also:
-
mode_auth_psk
public static final byte mode_auth_psk- See Also:
-
kem_P256_SHA256
public static final short kem_P256_SHA256- See Also:
-
kem_P384_SHA348
public static final short kem_P384_SHA348Deprecated.use kem_P384_SHA384- See Also:
-
kem_P384_SHA384
public static final short kem_P384_SHA384- See Also:
-
kem_P521_SHA512
public static final short kem_P521_SHA512- See Also:
-
kem_X25519_SHA256
public static final short kem_X25519_SHA256- See Also:
-
kem_X448_SHA512
public static final short kem_X448_SHA512- See Also:
-
kem_ML_KEM_512
public static final short kem_ML_KEM_512- See Also:
-
kem_ML_KEM_768
public static final short kem_ML_KEM_768- See Also:
-
kem_ML_KEM_1024
public static final short kem_ML_KEM_1024- See Also:
-
kem_MLKEM768_P256
public static final short kem_MLKEM768_P256- See Also:
-
kem_MLKEM1024_P384
public static final short kem_MLKEM1024_P384- See Also:
-
kem_X_WING
public static final short kem_X_WING- See Also:
-
kem_MLKEM768_X25519
public static final short kem_MLKEM768_X25519- See Also:
-
kdf_HKDF_SHA256
public static final short kdf_HKDF_SHA256- See Also:
-
kdf_HKDF_SHA384
public static final short kdf_HKDF_SHA384- See Also:
-
kdf_HKDF_SHA512
public static final short kdf_HKDF_SHA512- See Also:
-
aead_AES_GCM128
public static final short aead_AES_GCM128- See Also:
-
aead_AES_GCM256
public static final short aead_AES_GCM256- See Also:
-
aead_CHACHA20_POLY1305
public static final short aead_CHACHA20_POLY1305- See Also:
-
aead_EXPORT_ONLY
public static final short aead_EXPORT_ONLY- See Also:
-
-
Constructor Details
-
HPKE
public HPKE(byte mode, short kemId, short kdfId, short aeadId) Hybrid Public Key Encryption as described in RFC9180.- See Also:
-
HPKE
-
-
Method Details
-
getEncSize
public int getEncSize() -
getAeadId
public short getAeadId() -
generatePrivateKey
-
serializePublicKey
-
serializePrivateKey
-
deserializePublicKey
-
deserializePrivateKey
-
deriveKeyPair
-
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
-
setupBaseS
public HPKEContextWithEncapsulation setupBaseS(AsymmetricKeyParameter pkR, byte[] info, AsymmetricCipherKeyPair kpE) -
setupBaseS
-
setupBaseR
-
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)
-