/**
* Class Aes
*/
class Aes {
private $iv = '';//密钥偏移量IV,可自定义
private $encryptKey = '';//AESkey,可自定义
public function set_key($key){
$this->encryptKey = $key;
}
public function set_iv($iv){
$this->iv = $iv;
}
//加密
public function encrypt($encryptStr) {
$localIV = $this->iv;
$encryptKey = $this->encryptKey;
//Open module
$module = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_CBC, $localIV);
//print "module = $module <br/>" ;
mcrypt_generic_init($module, $encryptKey, $localIV);
//Padding
$block = mcrypt_get_block_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC);
$pad = $block - (strlen($encryptStr) % $block); //Compute how many characters need to pad
$encryptStr .= str_repeat(chr($pad), $pad); // Af
PHP 实现AES/CBC/PKCS5Padding加解密(对称加密)
最新推荐文章于 2024-09-19 11:40:16 发布
本文介绍了如何在PHP中使用AES/CBC/PKCS5Padding进行加解密操作,强调了urlsafe_b64encode()和urlsafe_b64decode()函数的重要性,这些函数用于数据的编码和解码。
摘要由CSDN通过智能技术生成