/*
* $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.