<?php
/**
 *
 * @author：llbjj
 * @DateTime：2022/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);
    }

}