{"id":15567368,"url":"https://github.com/dajiaji/pyhpke","last_synced_at":"2025-03-17T15:13:01.369Z","repository":{"id":63213626,"uuid":"559056422","full_name":"dajiaji/pyhpke","owner":"dajiaji","description":"A Python Implementation of HPKE (Hybrid Public Key Encryption)","archived":false,"fork":false,"pushed_at":"2025-03-16T05:30:40.000Z","size":2442,"stargazers_count":11,"open_issues_count":3,"forks_count":5,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-16T06:23:55.537Z","etag":null,"topics":["cryptography","e2ee","encryption","hpke","security"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dajiaji.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGES.rst","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-10-28T23:48:44.000Z","updated_at":"2025-03-16T05:30:44.000Z","dependencies_parsed_at":"2023-10-15T01:51:14.417Z","dependency_job_id":"fc66348a-8b88-4d4a-a9cb-71ec159e466b","html_url":"https://github.com/dajiaji/pyhpke","commit_stats":{"total_commits":233,"total_committers":7,"mean_commits":"33.285714285714285","dds":0.5064377682403434,"last_synced_commit":"4af30383e078d2fe5a6e7e560b066bd7d066555b"},"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dajiaji%2Fpyhpke","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dajiaji%2Fpyhpke/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dajiaji%2Fpyhpke/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dajiaji%2Fpyhpke/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dajiaji","download_url":"https://codeload.github.com/dajiaji/pyhpke/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244056425,"owners_count":20390719,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cryptography","e2ee","encryption","hpke","security"],"created_at":"2024-10-02T17:10:50.440Z","updated_at":"2025-03-17T15:13:01.341Z","avatar_url":"https://github.com/dajiaji.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PyHPKE - A Python implementation of HPKE\n\n[![PyPI version](https://badge.fury.io/py/pyhpke.svg)](https://badge.fury.io/py/pyhpke)\n![PyPI - Python Version](https://img.shields.io/pypi/pyversions/pyhpke)\n[![Documentation Status](https://readthedocs.org/projects/pyhpke/badge/?version=latest)](https://pyhpke.readthedocs.io/en/latest/?badge=latest)\n![Github CI](https://github.com/dajiaji/pyhpke/actions/workflows/ci.yml/badge.svg)\n[![codecov](https://codecov.io/gh/dajiaji/pyhpke/branch/main/graph/badge.svg?token=QN8GXEYEP3)](https://codecov.io/gh/dajiaji/pyhpke)\n\n\nPyHPKE is a [HPKE (Hybrid Public Key Encryption)](https://www.rfc-editor.org/rfc/rfc9180.html) implementation written in Python.\n\nYou can install PyHPKE with pip:\n\n```sh\n$ pip install pyhpke\n```\n\nAnd then, you can use it as follows:\n\n\n```py\nfrom pyhpke import AEADId, CipherSuite, KDFId, KEMId, KEMKey\n\n# The sender side:\nsuite_s = CipherSuite.new(\n    KEMId.DHKEM_P256_HKDF_SHA256, KDFId.HKDF_SHA256, AEADId.AES128_GCM\n)\npkr = KEMKey.from_jwk(  # from_pem is also available.\n    {\n        \"kid\": \"01\",\n        \"kty\": \"EC\",\n        \"crv\": \"P-256\",\n        \"x\": \"Ze2loSV3wrroKUN_4zhwGhCqo3Xhu1td4QjeQ5wIVR0\",\n        \"y\": \"HlLtdXARY_f55A3fnzQbPcm6hgr34Mp8p-nuzQCE0Zw\",\n    }\n)\nenc, sender = suite_s.create_sender_context(pkr)\nct = sender.seal(b\"Hello world!\")\n\n# The recipient side:\nsuite_r = CipherSuite.new(\n    KEMId.DHKEM_P256_HKDF_SHA256, KDFId.HKDF_SHA256, AEADId.AES128_GCM\n)\nskr = KEMKey.from_jwk(\n    {\n        \"kid\": \"01\",\n        \"kty\": \"EC\",\n        \"crv\": \"P-256\",\n        \"x\": \"Ze2loSV3wrroKUN_4zhwGhCqo3Xhu1td4QjeQ5wIVR0\",\n        \"y\": \"HlLtdXARY_f55A3fnzQbPcm6hgr34Mp8p-nuzQCE0Zw\",\n        \"d\": \"r_kHyZ-a06rmxM3yESK84r1otSg-aQcVStkRhA-iCM8\",\n    }\n)\nrecipient = suite_r.create_recipient_context(enc, skr)\npt = recipient.open(ct)\n\nassert pt == b\"Hello world!\"\n\n\n# deriving a KEMKeyPair\nkeypair = suite_s.kem.derive_key_pair(b\"some_ikm_bytes_used_for_key_derivation\")\n```\n\n## Index\n\n- [Installation](#installation)\n- [Supported HPKE Modes and Cipher Suites](#supported-hpke-modes-and-cipher-suites)\n- [Warnings and Restrictions](#warnings-and-restrictions)\n- [Usage](#usage)\n- [API Reference](#api-reference)\n- [Test](#test)\n- [Contributing](#contributing)\n\n## Installation\n\nYou can install PyHPKE with pip:\n\n```sh\n$ pip install pyhpke\n```\n\n## Supported HPKE Modes and Cipher Suites\n\nPyHPKE supports all of the HPKE modes and cipher suites defined in RFC9180 below.\n\n- modes\n    - ✅ Base\n    - ✅ PSK\n    - ✅ Auth\n    - ✅ AuthPSK\n- KEMs (Key Encapsulation Machanisms)\n    - ✅ DHKEM (P-256, HKDF-SHA256)\n    - ✅ DHKEM (P-384, HKDF-SHA384)\n    - ✅ DHKEM (P-521, HKDF-SHA512)\n    - ✅ DHKEM (X25519, HKDF-SHA256)\n    - ✅ DHKEM (X448, HKDF-SHA512)\n- KDFs (Key Derivation Functions)\n    - ✅ HKDF-SHA256\n    - ✅ HKDF-SHA384\n    - ✅ HKDF-SHA512\n- AEADs (Authenticated Encryption with Associated Data)\n    - ✅ AES-128-GCM\n    - ✅ AES-256-GCM\n    - ✅ ChaCha20Poly1305\n    - ✅ Export Only\n\n## Warnings and Restrictions\n\nAlthough this library has been passed all of the following official test vectors, it has not been formally audited.\n- [RFC9180 official test vectors provided on github.com/cfrg/draft-irtf-cfrg-hpke](https://github.com/cfrg/draft-irtf-cfrg-hpke/blob/5f503c564da00b0687b3de75f1dfbdfc4079ad31/test-vectors.json)\n\n## Usage\n\n```py\nfrom pyhpke import AEADId, CipherSuite, KDFId, KEMId, KEMKey\n\n# The sender side:\nsuite_s = CipherSuite.new(\n    KEMId.DHKEM_P256_HKDF_SHA256, KDFId.HKDF_SHA256, AEADId.AES128_GCM\n)\npkr = KEMKey.from_jwk(\n    {\n        \"kid\": \"01\",\n        \"kty\": \"EC\",\n        \"crv\": \"P-256\",\n        \"x\": \"Ze2loSV3wrroKUN_4zhwGhCqo3Xhu1td4QjeQ5wIVR0\",\n        \"y\": \"HlLtdXARY_f55A3fnzQbPcm6hgr34Mp8p-nuzQCE0Zw\",\n    }\n)\nenc, sender = suite_s.create_sender_context(pkr)\nct = sender.seal(b\"Hello world!\")\n\n# The recipient side:\nsuite_r = CipherSuite.new(\n    KEMId.DHKEM_P256_HKDF_SHA256, KDFId.HKDF_SHA256, AEADId.AES128_GCM\n)\nskr = KEMKey.from_jwk(\n    {\n        \"kid\": \"01\",\n        \"kty\": \"EC\",\n        \"crv\": \"P-256\",\n        \"x\": \"Ze2loSV3wrroKUN_4zhwGhCqo3Xhu1td4QjeQ5wIVR0\",\n        \"y\": \"HlLtdXARY_f55A3fnzQbPcm6hgr34Mp8p-nuzQCE0Zw\",\n        \"d\": \"r_kHyZ-a06rmxM3yESK84r1otSg-aQcVStkRhA-iCM8\",\n    }\n)\nrecipient = suite_r.create_recipient_context(enc, skr)\npt = recipient.open(ct)\n\nassert pt == b\"Hello world!\"\n```\n\n## API Reference\n\nSee [Documentation](https://pyhpke.readthedocs.io/en/stable/api.html).\n\n## Test\n\nYou can run tests from the project root after cloning with:\n\n```sh\n$ tox\n```\n\n## Contributing\n\nWe welcome all kind of contributions, filing issues, suggesting new features or sending PRs.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdajiaji%2Fpyhpke","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdajiaji%2Fpyhpke","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdajiaji%2Fpyhpke/lists"}