花粉解决方案 / 加密
花粉解决方案 - 加密组件 - 使用AES-256和AES-128加密进行加密和解密的工具。
v1.0.0
2021-08-12 00:00 UTC
Requires
- php: ^7.4 || ^8.0
- ext-openssl: *
- pollen-solutions/support: ^1.0
Requires (Dev)
- phpunit/phpunit: ^9.0
Suggests
- pollen-solutions/container: Pollen Solutions - Container Component - PSR-11 ready Dependencies Injection Container.
This package is auto-updated.
Last update: 2024-09-17 23:02:14 UTC
README
花粉解决方案 加密 组件提供通过OpenSSL使用AES-256和AES-128加密进行文本加密和解密的工具。
安装
composer require pollen-solutions/encryption
基本用法
use Pollen\Encryption\Encrypter; // Cypher (AES-128-CBC|AES-256-CBC) and Key definitions $cypher = 'AES-256-CBC'; // Recommended (use a static key. Replace 'static_key' by your own string) $key = md5('static_key'); // Dynamic random key (only valid during current request) // $key = Encrypter::generateKey($cypher); // Encrypter instanciation $encrypter = new Encrypter($key, $cypher); // To encrypt string $toEncrypt = 'toEncrypt'; // Encryption $encrypted = $encrypter->encrypt($toEncrypt); var_dump('encrypted string : ' . $encrypted); // ex. eyJpdiI6ImwxcmNicytwcVpkZmdsem4zTEpROVE9PSIsInZhbHVlIjoiK0JTN2EzWFVFazJoYi9abk1maW4vZz09IiwibWFjIjoiNDFiMzNlNzJkZjQxNGNhNmQyYmQ3MmViYjc0MTMyNmZiOTJmZTdlNDNmZmZiZGM3NzE1ZTc5YzE3YjIyZGQwZCJ9 // Décryption $decrypted = $encrypter->decrypt($encrypted); var_dump('decrypted string : ' . $decrypted); // >> toEncrypt