PyHPKE is a Python implementation of HPKE (Hybrid Public Key Encryption), providing mechanisms for authenticated encryption with associated data. It supports all HPKE modes and cipher suites defined in RFC9180. The library is currently at version 0.6.4 and maintains a regular release cadence with frequent minor updates and dependency bumps.
pip install pyhpkeVerified import paths — ran on the pinned version, not inferred.
This example demonstrates a basic HPKE 'Base' mode encryption and decryption flow. A sender creates a context using the recipient's public key, encapsulates a symmetric key, and seals a plaintext message. The recipient uses the encapsulated key and their private key to open the ciphertext.
Thoroughly review the codebase and cryptographic primitives or seek independent security audits for critical applications.
Upgrade Python to 3.10 or newer (the current minimum supported version is 3.10) or pin pyhpke to a version prior to 0.6.0.
Implement robust key management practices, securely generate and store keys, and use unique nonces for each encryption operation (e.g., using a secure random number generator).
Install the package using pip: `pip install pyhpke`.
Ensure all arguments (e.g., plaintext/ciphertext, nonce, AAD) conform to the expected types and lengths for the selected `CipherSuite` and method. Refer to the `pyhpke` API documentation for specific parameter requirements.
Review the setup of the `CipherSuite` and the `sender_context`, ensuring that valid KEM, KDF, and AEAD identifiers are used, and that the recipient's public key is correctly formatted. Verify the plaintext and associated authenticated data (AAD) for any non-conformant values.
Verify that the recipient's private key, the `enc` value obtained from the sender, the `nonce`, and the `aad` used during decryption exactly match those used during the original encryption. Ensure the correct `CipherSuite` is being used.