public static function encrypt($data, $key)
{
$key = 111;
// 生成盐值
$salt = openssl_random_pseudo_bytes(16);
// 使用盐值和密钥进行加密
$encrypted = openssl_encrypt($data, 'AES-128-CBC', $key, 0, $salt);
// 将盐值和加密后的数据拼接
$result = base64_encode($salt . $encrypted);
return $result;
}
public static function decrypt($data, $key)
{
$key = 111;
// 解码数据
$data = base64_decode($data);
// 从数据中提取盐值和加密的数据
$salt = substr($data, 0, 16);
$encrypted = substr($data, 16);
// 使用盐值和密钥进行解密
$decrypted = openssl_decrypt($encrypted, 'AES-128-CBC', $key, 0, $salt);
return $decrypted;
}