ade_4d3 / php-crypto-wrapper
Encryption operations wrapper with sodium for PHP
v1.1.0
2025-12-20 06:59 UTC
Requires
- php: >=8.2
- ext-sodium: *
This package is not auto-updated.
Last update: 2026-03-29 07:01:51 UTC
README
This is a wrapper of sodium for simplifyty cryptograpy operations Empaquetado para simplificación de operaciones criptográficas usando Sodium
This is Free Software with MIT License/ Software libre bajo licencia MIT
Aviable:
- Argon2id
- AES-256-GCM
- ChaCha20-Poly1305
Usage
use PhpCryptoWrapper
Argon
use PhpCryptoWrapper\Argon;
Argon::hash($pass);
Argon::verify($text, $hash); // return bool
$salt = Argon::salt();
Argon::derivation($length, $salt, $text); // Derive a password however or with SODIUM_CRYPTO_AEAD_AES256GCM_KEYBYTES
AES
use PhpCryptoWrapper\AES;
$key = AES::genKey(); // O you can use Argon::derivation with SODIUM_CRYPTO_AEAD_AES256GCM_KEYBYTES
$additional_data = // Any data ...
[$nonce, $ciphertext] = AES::encrypt($plaintext, $additional_data, $key);
$plaintext = AES::decrypt($ciphertext, $additional_data, $nonce, $key)
ChaCha20Poly1320
use PhpCryptoWrapper\ChaCha20Poly1305;
// [
// "ChaCha20Poly1305",
// "ChaCha20Poly1305-IETF",
// "XChaCha20Poly1305",
// ]
$chacha20 = new ChaCha20Poly1305($algo); // By default XChaCha20Poly1305
$key = $chacha20->genKey(); // Key o wiht Argon
$additional_data = "anydata";
[$nonce, $ct] = $chacha20->encrypt("Asupersecret", $additional_data, $key);
echo $chacha20->decrypt($ct, $additional_data, $nonce, $key) . "\n";