temant / encryption-manager
一个全面的PHP加密解密库
v1.0.1
2024-09-12 08:38 UTC
Requires
- php: >=8.3
Requires (Dev)
- phpstan/phpstan: ^1.11
- phpunit/phpunit: ^11.2
This package is not auto-updated.
Last update: 2024-09-27 07:14:25 UTC
README
Temant Encryption Manager是一个简单且安全的PHP加密库。它提供了一组易于使用的API,用于使用AES-128-CBC和AES-256-CBC加密算法对字符串和文件进行加密和解密。
安装
您可以使用Composer安装此库
composer require temant/encryption-manager
用法
加密
加密字符串
use Temant\EncryptionManager\EncryptionManager; use Temant\EncryptionManager\EncryptionTypeEnum; // Initialize the Encryption class with a key $encryption = new EncryptionManager('your-encryption-key', EncryptionTypeEnum::BYTES_256); // Encrypt a string $plainText = 'Hello, World!'; $encrypted = $encryption->encryptString($plainText); // Decrypt the string $decrypted = $encryption->decryptString($encrypted); echo "Encrypted: $encrypted\n"; echo "Decrypted: $decrypted\n";
使用密码加密
使用密码加密字符串
$plainText = 'Sensitive Data'; $password = 'your-secure-password'; $encrypted = $encryption->encryptString($plainText, $password); $decrypted = $encryption->decryptString($encrypted, $password); echo "Encrypted: $encrypted\n"; echo "Decrypted: $decrypted\n";
文件加密
加密和解密文件
// Encrypt a file $inputFile = 'path/to/input/file.txt'; $encryptedFile = 'path/to/encrypted/file.txt'; $password = 'file-password'; $encryption->encryptFile($inputFile, $encryptedFile, $password); // Decrypt the file $decryptedFile = 'path/to/decrypted/file.txt'; $encryption->decryptFile($encryptedFile, $decryptedFile, $password); $decryptedContent = file_get_contents($decryptedFile); echo "Decrypted file content: $decryptedContent\n";
运行测试
要运行测试,请使用以下命令
vendor/bin/phpunit
许可证
本项目采用BSD 3-Clause许可证。