Symmetric encryption
AES-256-GCM, XChaCha20, AES-256-CBC-HMAC, SM4-CBC and ZUC-128.
PHP / Cryptography + Rust
Symmetric, asymmetric, hashing and KDF, plus Chinese SM algorithms, share one contract system.
Application code depends only on contracts, so switching AES-256-GCM, XChaCha20 or an SM algorithm needs no business-logic change.
EncryptionManagerFactory derives one subkey per algorithm from a 32-byte master key and registers every encryptor at once.
A friendly padlock with a smiling keyhole, one hand waving and the other holding a golden key: a pluggable crypto library for symmetric, asymmetric, hashing, KDF and SM algorithms.
One key per algorithm, a fresh IV per call.Contract, registry, facade and implementation cover every algorithm family.
AES-256-GCM, XChaCha20, AES-256-CBC-HMAC, SM4-CBC and ZUC-128.
SM2 takes a public and private key per call, using hex keys and ciphertext with ext-gmp.
SHA-256 and SM3 return a 32-byte digest for signing and integrity checks.
HKDF-SHA256 expands high-entropy keys; PBKDF2-SHA256 defaults to 310000 iterations.
SM2, SM3, SM4 and ZUC share one contract; SM1, SM7 and SM9 are explicitly unsupported.
Add an algorithm with one interface and register(); the registry and facade stay unchanged.
The same algorithm identifiers as the PHP version, ready in Rust.
Pluggable cryptography for Rust
Eight capability families behind one contract: symmetric, asymmetric, hashing, KDF, password KDF, signing, key agreement and encapsulation, with SM2/SM3/SM4/ZUC and ML-KEM.
From symmetric encryption to SM algorithms and plain PHP support.
Add optional v2 subkey derivation and fix HMAC argument order; speed up ZUC keystreams and add PHPStan and i18n CI.
Fix the SM2 reflection error on PHP 8.0; prefer native OpenSSL for SM3/SM4 and expand CI and security policy.
Add a runnable examples/plain-php flow covering encryption, storage, decryption and tamper detection.
Add the Mascot API, four design diagrams, docs/i18n in 12 languages and localized SVGs.
Click an image to enlarge.
Install, then run a minimal example.
composer require erikwang2013/encryption:^1.0use Erikwang2013\Encryption\Encryptor\Aes256GcmEncryptor;
$key = random_bytes(32);
$encryptor = new Aes256GcmEncryptor($key);
$ciphertext = $encryptor->encrypt('plaintext');
$plaintext = $encryptor->decrypt($ciphertext);cargo add encryption-rustuse encryption::factory::EncryptionManagerFactory;
let master_key: [u8; 32] = load_master_key();
let manager = EncryptionManagerFactory::from_master_key(&master_key, "aes-256-gcm")?;
let stored = manager.encrypt(phone.as_bytes())?;
let phone = manager.decrypt(&stored)?;Hover and the mood changes.