soatok / age
Pure-PHP implementation of the age file encryption format (c2sp.org/age)
dev-main
2026-04-11 17:20 UTC
Requires
- php: ^8.2
- paragonie/constant_time_encoding: ^3
- paragonie/hpke: ^0.7
- paragonie/pqcrypto_compat: ^0|^1
- paragonie/sodium_compat: ^2
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.5
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^10|^11|^12|^13
- soatok/code-style: >= 0
- vimeo/psalm: ^6
Suggests
- ext-pqcrypto: Better performance and security for post-quantum cryptography
This package is auto-updated.
Last update: 2026-04-11 17:20:58 UTC
README
PHP implementation of age. Supports post-quantum cryptography.
Tip
The author pronounces it [aɡe̞] with a hard g, like GIF, and it's
always spelled lowercase.
Installation
composer require soatok/age
Usage
We ecommend using Hybrid ML-KEM-768 + X25519 for identities and recipients.
<?php use Soatok\Age\Age; use Soatok\Age\Hybrid\Mlkem768X25519\{ HybridIdentity, HybridRecipient }; // Generate a new identity for Alice: $alice = HybridIdentity::generate(); // You can use HybridRecipient::fromString(/* age public key goes here */); to load a public key // For a runnable example, we generate Bob's on-the-fly: $bobSecret = HybridIdentity::generate(); $bob = $bobSecret->getRecipient(); // Sample encryption: $aliceToBob = Age::encrypt('hello bob', [$bob]); // Example decryption: $bobReads = Age::decrypt($aliceToBob, [$bobSecret]); var_dump($bobReads); // string(9) "hello bob" // With optional ASCII armor: $bobToAlice = Age::encryptArmored('hi alice!', [$alice->getRecipient()]); $aliceReads = Age::decrypt($bobToAlice, [$alice]); var_dump($aliceReads); // string(9) "hi alice!"
Limitations
- P-256 is currently not implemented
- Nor is Hybrid ML-KEM-768 + P-256
- Scrypt is not supported
License
This PHP port of age is released under the same 3-Clause BSD license as the Go implementation.