php aes 128 CBC加密、解密函数 php aes mcrypt php aes ecb php java aes加密解
程序员文章站
2022-06-10 17:58:55
...
/*
$padding = 16 - (strlen($data) % 16);
$data .= str_repeat(chr($padding), $padding);
$encrypted = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $data, MCRYPT_MODE_CBC, $iv);
return base64_encode($encrypted);
}
function cbc_decrypt($data,$key) {
$iv = $key;
$data = base64_decode($data);
$data = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $key, $data, MCRYPT_MODE_CBC, $iv);
$padding = ord($data[strlen($data) - 1]);
return substr($data, 0, -$padding);
}
* $data 加密的内容,$key 密钥
*/
function cbc_encrypt($data ,$key ) {
$iv = $key;$padding = 16 - (strlen($data) % 16);
$data .= str_repeat(chr($padding), $padding);
$encrypted = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $data, MCRYPT_MODE_CBC, $iv);
return base64_encode($encrypted);
}
function cbc_decrypt($data,$key) {
$iv = $key;
$data = base64_decode($data);
$data = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $key, $data, MCRYPT_MODE_CBC, $iv);
$padding = ord($data[strlen($data) - 1]);
return substr($data, 0, -$padding);
}
以上就介绍了php aes 128 CBC加密、解密函数,包括了php,aes方面的内容,希望对PHP教程有兴趣的朋友有所帮助。
上一篇: ThinkPHP小白 POST无效
下一篇: 页面无动作,5分钟后自动退出系统