PHP
<?php
class CryptographyHelper
{
const cipher = 'AES-256-CBC';
/**
* 加密 $text 需加密内容 $key Appid $v AppSecret
* @param string $text
* @param string $key
* @param string $iv
* @return string
*/
public static function EncryptAES256(string $text, string $key, string $iv): string
{
$encrypt = openssl_encrypt($text, self::cipher, $key, OPENSSL_RAW_DATA, $iv);
return base64_encode($encrypt);
}
/**
* 解密 $text 需解密内容 $key Appid $v AppSecret
* @param string $text
* @param string $key
* @param string $iv
* @return string
*/
public static function DecryptAES256(string $text, string $key, string $iv): string
{
$decodeText = base64_decode($text);
return openssl_decrypt($decodeText, self::cipher, $key, OPENSSL_RAW_DATA, $iv);
}
}Last updated