php aes 128 CBC加密、解密函数 php aes mcrypt php aes ecb php java aes加密解
程序员文章站
2022-05-18 22:18:40
...
/*
$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教程有兴趣的朋友有所帮助。
上一篇: python登陆asp网站页面的实现代码
下一篇: 0 == 'ab' 好诡异的问题