PHP > AES 对称加密

 

 

需要打开 mcrypt  扩展

 

function ecryptdString($str,$keys,$iv="8105547186756232",$cipher_alg=MCRYPT_RIJNDAEL_128){
    $encrypted_string = bin2hex(mcrypt_encrypt($cipher_alg, $keys, $str, MCRYPT_MODE_CBC,$iv));
    return $encrypted_string;
}
/*
* 实现AES解密
* $str : 要解密的字符串
* $keys : 加密密钥
* $iv : 加密向量
* $cipher_alg : 加密方式
*/
function decryptStrin($str,$keys,$iv="8105547186756232",$cipher_alg=MCRYPT_RIJNDAEL_128){
    $decrypted_string = mcrypt_decrypt($cipher_alg, $keys, pack("H*",$str),MCRYPT_MODE_CBC, $iv);
    return $decrypted_string;
}

define("KEY","wo shi key");
$content = '我是内容ase';

$encrypt = ecryptdString($content,KEY);
echo $encrypt;

echo '<BR>';
echo decryptStrin($encrypt,KEY);

 

 

6321893597b379726748a1eeac7091ee
我是内容ase

 

你可能感兴趣的:(对称加密)