ghazali / laravel-hybrid-crypto
A Laravel package for hybrid encryption using P-384, X25519, and ML-KEM-768.
Package info
github.com/codeWithDevMA/laravel-hybrid-crypto
pkg:composer/ghazali/laravel-hybrid-crypto
v1.0.1
2026-11-25 22:07 UTC
Requires
- php: ^8.2
- illuminate/auth: ^10.0|^11.0|^12.0|^13.0
- illuminate/cache: ^10.0|^11.0|^12.0|^13.0
- illuminate/database: ^10.0|^11.0|^12.0|^13.0
- illuminate/filesystem: ^10.0|^11.0|^12.0|^13.0
- illuminate/http: ^10.0|^11.0|^12.0|^13.0
- illuminate/routing: ^10.0|^11.0|^12.0|^13.0
- illuminate/session: ^10.0|^11.0|^12.0|^13.0
- illuminate/support: ^10.0|^11.0|^12.0|^13.0
- illuminate/validation: ^10.0|^11.0|^12.0|^13.0
- laravel/framework: ^13.8
- laravel/tinker: ^3.0
- paragonie/pqcrypto_compat: ^0.3.2
- paragonie/sodium_compat: ^2.0
- phpseclib/phpseclib: ^3.0
- spatie/laravel-package-tools: ^1.16
Requires (Dev)
- fakerphp/faker: ^1.23
- laravel/pail: ^1.2.5
- laravel/pao: ^1.0.6
- laravel/pint: ^1.27
- mockery/mockery: ^1.6
- nunomaduro/collision: ^8.6
- orchestra/testbench: ^8.0|^9.0|^10.0|^11.0
- phpunit/phpunit: ^12.5.12
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
A Laravel package for hybrid cryptography support (P-256, P-384, X25519, and ML-KEM-768) designed for easy integration with frontend and mobile SDKs (like Flutter).
Installation
Install via Composer:
composer require ghazali/laravel-hybrid-crypto
Publish the configuration file:
php artisan vendor:publish --provider="Vendor\HybridCrypto\HybridCryptoServiceProvider"
Features
- Manual Controller/Service Layer Encryption: Encrypt and decrypt payloads explicitly without Eloquent model magic.
- Multiple Curves & Post-Quantum Support: Supports P-256 (
prime256v1), P-384 (secp384r1), X25519 (ecdh), and ML-KEM-768 (mlkem768). - Standardized AES-256-GCM Envelope: Outputs
iv,gcmNonce,ephemeral_public_key,encrypted, andtag. - Ephemeral Session Mode (Zero Disk Storage): Generate challenge keypairs in memory and decrypt payloads on-the-fly without storing private keys on disk.
Quick Start
Encrypt Data
use Vendor\HybridCrypto\Facades\HybridCrypto; $receiverPublicKey = HybridCrypto::publicKey('p256'); // or 'ecdh' / 'mlkem768' $payload = HybridCrypto::encryptData($data, $salt, $receiverPublicKey);
Decrypt Data
$decrypted = HybridCrypto::decryptData($payload, $salt, $payload['public_key']);
Ephemeral Session Mode
$keyMaterial = HybridCrypto::generateEphemeralKeyPair('p256'); // Store $keyMaterial in session/cache and send $keyMaterial['public_key_b64'] to the client
Documentation
- Read USAGE.md for the integration guide, payload formats, and ephemeral session key management.
- For
anti_qcp=true, the server selects ML-KEM-768 automatically. Otherwise, standard elliptic curve cryptography (ECC) algorithms are used and clients infer the exact algorithm from the public key.
License
This package is open-sourced software licensed under the MIT license.