PHP 中的 AES-256 加密
我需要一个 PHP 函数,AES256_encode($dataToEcrypt)
将 $data
加密成 AES-256 和另一个 AES256_decode($encryptedData)
代码>做相反的事情.有谁知道这个函数应该有什么代码?
I need a PHP function, AES256_encode($dataToEcrypt)
to encrypt the $data
into AES-256 and another one AES256_decode($encryptedData)
do the opposite. Does anyone know what code should this functions have?
推荐答案
看mcrypt模块
AES-Rijndael 示例取自 此处
AES-Rijndael example taken from here
$iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC);
$iv = mcrypt_create_iv($iv_size, MCRYPT_DEV_URANDOM);
$key = pack('H*', "bcb04b7e103a0cd8b54763051cef08bc55abe029fdebae5e1d417e2ffb2a00a3");
# show key size use either 16, 24 or 32 byte keys for AES-128, 192
# and 256 respectively
$key_size = strlen($key);
echo "Key size: " . $key_size . "
";
$text = "Meet me at 11 o'clock behind the monument.";
echo strlen($text) . "
";
$crypttext = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $text, MCRYPT_MODE_CBC, $iv);
echo strlen($crypttext) . "
";
这是解密函数
相关文章