Home >Backend Development >PHP Tutorial >php aes 128 CBC encryption and decryption function php aes mcrypt php aes ecb php java aes encryption solution

php aes 128 CBC encryption and decryption function php aes mcrypt php aes ecb php java aes encryption solution

WBOY
WBOYOriginal
2016-07-29 08:48:411690browse

/*

* $data encrypted content, $key 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);
}

The above introduces the php aes 128 CBC encryption and decryption functions, including php and aes content. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn