{"id":28972871,"url":"https://github.com/paragonie/hpke-php","last_synced_at":"2026-04-17T02:01:05.630Z","repository":{"id":275702877,"uuid":"923395625","full_name":"paragonie/hpke-php","owner":"paragonie","description":"PHP Implementation of RFC 9180 (Hybrid Public-Key Encryption)","archived":false,"fork":false,"pushed_at":"2026-04-08T21:58:39.000Z","size":1775,"stargazers_count":8,"open_issues_count":0,"forks_count":3,"subscribers_count":4,"default_branch":"main","last_synced_at":"2026-04-08T23:32:36.374Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/paragonie.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-01-28T06:48:59.000Z","updated_at":"2026-04-08T21:57:58.000Z","dependencies_parsed_at":null,"dependency_job_id":"997f7744-0db5-42e4-b3db-186701549a3d","html_url":"https://github.com/paragonie/hpke-php","commit_stats":null,"previous_names":["paragonie/hpke-php"],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/paragonie/hpke-php","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paragonie%2Fhpke-php","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paragonie%2Fhpke-php/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paragonie%2Fhpke-php/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paragonie%2Fhpke-php/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/paragonie","download_url":"https://codeload.github.com/paragonie/hpke-php/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paragonie%2Fhpke-php/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31911846,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-16T18:22:33.417Z","status":"online","status_checked_at":"2026-04-17T02:00:06.879Z","response_time":62,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2025-06-24T11:32:28.599Z","updated_at":"2026-04-17T02:01:05.609Z","avatar_url":"https://github.com/paragonie.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Hybrid Public-Key Encryption (HPKE, RFC 9180) for PHP\n\n[![Build Status](https://github.com/paragonie/hpke-php/actions/workflows/test.yml/badge.svg)](https://github.com/paragonie/hpke-php/actions)\n[![Latest Stable Version](https://poser.pugx.org/paragonie/hpke/v/stable)](https://packagist.org/packages/paragonie/hpke)\n[![Total Downloads](https://poser.pugx.org/paragonie/hpke/downloads)](https://packagist.org/packages/paragonie/hpke)\n[![Latest Unstable Version](https://poser.pugx.org/paragonie/hpke/v/unstable)](https://packagist.org/packages/paragonie/hpke)\n[![License](https://poser.pugx.org/paragonie/hpke/license)](https://packagist.org/packages/paragonie/hpke)\n\n## Installation\n\n```terminal\ncomposer require paragonie/hpke\n```\n\n## Usage\n\n### Instantiating HPKE\n\nFirst, you need to decide on an HPKE ciphersuite. You can build these yourself by component, or use the standard modes\nthat ship with [RFC 9180](https://www.rfc-editor.org/rfc/rfc9180.html#name-iana-considerations):\n\n* DHKEM(X25519, HKDF-SHA256), HKDF-SHA256, AES-128-GCM\n* DHKEM(X25519, HKDF-SHA256), HKDF-SHA256, ChaCha20Poly1305\n* DHKEM(P-256, HKDF-SHA256), HKDF-SHA256, AES-128-GCM\n* DHKEM(P-256, HKDF-SHA256), HKDF-SHA512, AES-128-GCM\n* DHKEM(P-256, HKDF-SHA256), HKDF-SHA256, ChaCha20Poly1305\n* DHKEM(P-521, HKDF-SHA512), HKDF-SHA512, AES-256-GCM\n\nAdditional Post-Quantum KEMs:\n\n* MLKEM768-X25519, HKDF-SHA256, AES-128-GCM\n* ML-KEM-768, HKDF-SHA256, AES-128-GCM\n* ML-KEM-1024, HKDF-SHA256, AES-256-GCM\n* MLKEM768-X25519, HKDF-SHA256, ChaCha20Poly1305\n* ML-KEM-768, HKDF-SHA256, ChaCha20Poly1305\n* ML-KEM-1024, HKDF-SHA256, ChaCha20Poly1305\n\n\u003e [!TIP]\n\u003e We recommend enabling opcache and JIT if you cannot install the \n\u003e [pqcrypto extension](https://github.com/paragonie/ext-pqcrypto).\n\nTo instantiate one of these ciphersuites, you can use the Factory class, like so:\n```php\n\u003c?php\nuse ParagonIE\\HPKE\\Factory;\n\n// Either approach will work fine.\n$ciphersuite = Factory::init('DHKEM(X25519, HKDF-SHA256), HKDF-SHA256, AES-128-GCM');\n$otherCS = Factory::dhkem_p256sha256_hkdf_sha256_chacha20poly1305();\n```\n\n### Generating and Managing Key Pairs\n\nOnce you've instantiated your ciphersuite, you can now use it to generate/load keys.\n\n```php\n\u003c?php\nuse ParagonIE\\HPKE\\HPKE;\nuse ParagonIE\\HPKE\\KEM\\DHKEM\\{DecapsKey, EncapsKey};\nuse Mdanter\\Ecc\\Serializer\\{\n    PublicKey\\PemPublicKeySerializer,\n    PrivateKey\\PemPrivateKeySerializer\n};\n\n/** @var HPKE $hpke */\n\n/**\n * @var EncapsKey $public\n * @var DecapsKey $secret\n */\n[$secret, $public] = $hpke-\u003ekem-\u003egenerateKeys();\n\n// You can now use Easy-ECC or PHP-ECC to manage these keys:\n$decapsulationKeyToSaveToDisk = (new PemPrivateKeySerializer())\n    -\u003eserialize($secret-\u003etoPrivateKey());\n\n$encapsKeySharePublicly = (new PemPublicKeySerializer())\n    -\u003eserialize($public-\u003etoPublicKey());\n```\n\n### Setting Up Encryption Contexts\n\nTo set up an encryption context, simply use the `setupBaseSender()` and `setupBaseReceiver()`\nAPIs.\n\n```php\n\u003c?php\nuse ParagonIE\\HPKE\\HPKE;\nuse ParagonIE\\HPKE\\KEM\\DHKEM\\{DecapsKey, EncapsKey};\n\n/** \n * @var HPKE $hpke \n * @var EncapsKey $public\n * @var DecapsKey $secret\n */\n \nconst INFO = 'my custom protocol name';\n\n// On one side\n[$enc, $sender] = $hpke-\u003esetupBaseSender($public, INFO);\n\n// On te other\n$receiver = $hpke-\u003esetupBaseReceiver($secret, $enc, INFO);\n\n// And now you can encrypt/decrypt:\n$encrypted1 = $sender-\u003eseal('test message', 'first message AAD');\n$decrypted1 = $receiver-\u003eopen($encrypted1, 'first message AAD');\n\n// The sequence is advanced automatically by our API\n```\n\n### One-Shot Encryption API\n\n```php\n\u003c?php\nuse ParagonIE\\HPKE\\HPKE;\nuse ParagonIE\\HPKE\\KEM\\DHKEM\\{DecapsKey, EncapsKey};\n\n/** \n * @var HPKE $hpke \n * @var EncapsKey $public\n * @var DecapsKey $secret\n */\n \nconst INFO = 'my custom protocol name';\n\n// Sending (encryption)\n$sealed = $hpke-\u003esealBase($public, 'plaintext message', 'aad', INFO);\n\n// Receiving (decryption)\n$opened = $hpke-\u003eopenBase($secret, $sealed, 'aad', INFO);\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fparagonie%2Fhpke-php","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fparagonie%2Fhpke-php","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fparagonie%2Fhpke-php/lists"}