crowdstar / crypt
处理数据加密/解密。
2.0.1
2021-11-04 19:47 UTC
Requires
- php: >=7.4
- phpseclib/phpseclib: ~3.0.0
Requires (Dev)
- phpunit/phpunit: ~8.0|~9.0
This package is auto-updated.
Last update: 2024-09-09 22:31:13 UTC
README
摘要
crypt 包为 phpseclib AES-128 库创建了一个简单的接口。其接口允许对字符串进行加密和解密,并通过 base64 编码实现初始化向量的编码,便于传输。
安装
composer require crowdstar/crypt:~2.0.0
示例用法
在使用库之前,您需要选择一个密钥,其大小只能是 16、24 或 32 位。
<?php $secretKey = "1234567890123456";
1. 加密并编码明文数据以进行存储或传输
<?php use CrowdStar\Crypt\Crypt; $encodedEncryptedData = (new Crypt($secretKey))->encrypt("message");
2. 解码和解析存储或接收的数据
<?php use CrowdStar\Crypt\Crypt; $encodedEncryptedData = (new Crypt($secretKey))->decrypt("encoded_encrypted_data");
3. 使用不同长度的初始化向量进行加密和解密
<?php use CrowdStar\Crypt\Crypt; $crypt = new Crypt($secretKey); $alternateIVLength = 8; $encodedEncryptedData = $crypt->encrypt("message", $alternateIVLength); $plainText = $crypt->decrypt($encodedEncryptedData, $alternateIVLength);
当传入错误数据时,方法调用 CrowdStar\Crypt\Crypt::decrypt()
的返回值将为空字符串。