Files
admin/module/Application/src/Common/Crypt.php
2025-09-13 01:22:15 +08:00

48 lines
1.2 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
/**
*
* @authorllbjj
* @DateTime2022/5/5 18:20
* @Description
*
*/
namespace Application\Common;
use Laminas\Crypt\BlockCipher;
use Laminas\Crypt\Key\Derivation\Pbkdf2;
use Laminas\Crypt\Key\Derivation\Scrypt;
use Laminas\Crypt\Password\Bcrypt;
use Laminas\Crypt\Password\BcryptSha;
use Laminas\Math\Rand;
class Crypt
{
/**
* Notes: 对称加解密 使用例子Crypt::blockCipher()->encrypt($data) Crypt::blockCipher()->decrypt($data)
* User: llbjj
* DateTime: 2022/5/5 18:48
*
* @return BlockCipher
*/
static function blockCipher() {
$blockCipher = BlockCipher::factory('openssl', ['algo' => 'aes', 'mode' => 'gcm']);
$blockCipher->setKey('ae60e54db83a30ea985fcd77b14c063320922864a584c5dfb96e77d84e7317aa');
return $blockCipher;
}
/**
* Notes: 获取加密字符串
* User: llbjj
* DateTime: 2022/5/5 19:12
*
* @param string $data
* @return string
*/
static function createKey(string $data = 'YikeenEDC') {
$salt = Rand::getBytes(32, true);
$key = Scrypt::calc($data, $salt, 2048, 3, 1, 32);
return bin2hex($key);
}
}