bewor/php-cryptography
最新稳定版本:v2.0.0
Composer 安装命令:
composer require bewor/php-cryptography
包简介
Encryption Library
关键字:
README 文档
README
Requirements
PHP 8.2 or higher.
Installation
Require this package in your composer.json and update composer. This will download the package.
composer require bewor/php-cryptography
Using
You can create a new Cryptography encrypter instance with any encrypt method allowed on openssl https://php.net/manual/en/function.openssl-encrypt.php.
use Bewor\PhpCryptography\Encrypt;
$encrypter = new Encrypt('aes-256-cbc', $publicKey);
$data = '[data to encrypt]';
$password = Encrypt::randomPassword();
$encryptedPassword = $encrypter->encryptPublicKey($password);
$encrypted = $encrypter->encrypt($data, $password);
$base64encrypted = $encrypter->encryptBase64($data, $password);
or create a new Cryptography decrypter instance with any decrypt method allowed on openssl https://www.php.net/manual/en/function.openssl-decrypt.php.
use Bewor\PhpCryptography\Decrypt;
$decrypter = new Decrypt('aes-256-cbc', $privateKey);
$data = '[data encrypted]';
...
$decryptedPassword = $decrypter->decryptPrivateKey($password);
$decrypted = $decrypter->decrypt($data, $decryptedPassword);
$base64decrypted = $decrypter->decryptBase64($data, $decryptedPassword);
You can also work with files instead of content.
use Bewor\PhpCryptography\Encrypt;
use Bewor\PhpCryptography\Decrypt;
$encrypter = new Encrypt('aes-256-cbc', $publicKey);
$decrypter = new Decrypt('aes-256-cbc', $privateKey);
$filePath = 'path/to/file';
...
$encrypted = $encrypter->encrypt($filePath, $password, true);
$base64encrypted = $encrypter->encryptBase64($filePath, $password, true);
$decrypted = $decrypter->decrypt($filePath, $password, true);
$base64decrypted = $decrypter->decryptBase64($filePath, $password, true);
统计信息
- 总下载量: 156
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 2
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-06-05