PHP / Cryptography + Rust

One contractEvery cipher

Symmetric, asymmetric, hashing and KDF, plus Chinese SM algorithms, share one contract system.

Locky the padlock mascot, the encryption project pet

Interfaces first, algorithms swappable

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.

  • Five symmetric ciphers
  • Hashing and key derivation
  • SM2/SM3/SM4/ZUC
5Symmetric ciphers
6Capability families
v1.4.0Current version
Locky the padlock mascot Smile expression

Locky

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.

Six capability families, one contract

Contract, registry, facade and implementation cover every algorithm family.

Symmetric encryption

AES-256-GCM, XChaCha20, AES-256-CBC-HMAC, SM4-CBC and ZUC-128.

Asymmetric encryption

SM2 takes a public and private key per call, using hex keys and ciphertext with ext-gmp.

Hashing

SHA-256 and SM3 return a 32-byte digest for signing and integrity checks.

Key derivation

HKDF-SHA256 expands high-entropy keys; PBKDF2-SHA256 defaults to 310000 iterations.

Chinese algorithms

SM2, SM3, SM4 and ZUC share one contract; SM1, SM7 and SM9 are explicitly unsupported.

Pluggable registry

Add an algorithm with one interface and register(); the registry and facade stay unchanged.

Same capability, Rust version

The same algorithm identifiers as the PHP version, ready in Rust.

Rust v1.3.0 Rust 1.88 / crate

encryption-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.

  • Eight families, one contract
  • SM2/SM3/SM4/ZUC
  • Ten algorithm identifiers
View Rust repository

How the algorithms arrived

From symmetric encryption to SM algorithms and plain PHP support.

v1.4.0

v2 derivation and faster ZUC

Add optional v2 subkey derivation and fix HMAC argument order; speed up ZUC keystreams and add PHPStan and i18n CI.

v1.3.0

SM2 fix and native OpenSSL

Fix the SM2 reflection error on PHP 8.0; prefer native OpenSSL for SM3/SM4 and expand CI and security policy.

v1.2.0

Plain PHP example

Add a runnable examples/plain-php flow covering encryption, storage, decryption and tamper detection.

v1.1.0

Mascot and translated docs

Add the Mascot API, four design diagrams, docs/i18n in 12 languages and localized SVGs.

Changelog

Recent releases, with the full list on GitHub Releases.

Latest v1.4.0 All versions
v1.4.02026-09-25

Optional v2 subkey derivation, faster ZUC keystreams, PHPStan and i18n checks.

v1.3.12026-09-25

Fix the Sm2AsymmetricCipher test setup error exposed by CI.

v1.3.02026-09-25

Fix SM2 reflection on PHP 8.0; use native OpenSSL for SM3/SM4.

v1.2.12026-09-25

Correct two entries in the project tree of translated READMEs.

v1.2.02026-09-25

Add the native PHP example and sync docs in 11 languages.

v1.1.12026-09-25

Unify terminology across translated docs and rewrite AGENTS.md.

Install and use

Install, then run a minimal example.

PHP >= 8.0Full README
Install
composer require erikwang2013/encryption:^1.0
Minimal example
use Erikwang2013\Encryption\Encryptor\Aes256GcmEncryptor;

$key = random_bytes(32);
$encryptor = new Aes256GcmEncryptor($key);
$ciphertext = $encryptor->encrypt('plaintext');
$plaintext = $encryptor->decrypt($ciphertext);

Locky's 12 expressions

Hover and the mood changes.

Search this site

Try “upload”, “migration” or “JWT”.