原文链接 https://blog.csdn.net/tangpanqing/article/details/71117822
AES 加密解密 接口开发很重要的环节
PHP 代码
$text = 'After all, tomorrow is another day.';
$key = pack('H*', 'e10adc3949ba59abbe56e057f20f883e'); //md5('123456')
$iv = pack('H*', '1234567890abcdef1234567890abcdef');
$encrypted = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $text, MCRYPT_MODE_CBC, $iv);
$encrypted = base64_encode($encrypted);
var_dump($encrypted);
$dncrypted = base64_decode($encrypted);
$dncrypted = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $key, $dncrypted, MCRYPT_MODE_CBC, $iv);
$dncrypted = trim($dncrypted);
var_dump($dncrypted);
JS 代码
var text = "After all, tomorrow is another day.";
var key = CryptoJS.enc.Hex.parse("e10adc3949ba59abbe56e057f20f883e"); //md5('123456')
var iv = CryptoJS.enc.Hex.parse("1234567890abcdef1234567890abcdef");
var opinion = {iv:iv, padding:CryptoJS.pad.ZeroPadding};
var encrypted = CryptoJS.AES.encrypt(text, key, opinion);
encrypted = encrypted.toString();
console.log(encrypted);
var decrypted = CryptoJS.AES.decrypt(encrypted, key, opinion);
decrypted = decrypted.toString(CryptoJS.enc.Utf8);
console.log(decrypted);
记得引用 CryptoJS
<script type="text/javascript" src="http://cdn.bootcss.com/crypto-js/3.1.9/crypto-js.js"></script>
<script type="text/javascript" src="http://cdn.bootcss.com/crypto-js/3.1.9/aes.js"></script>
正文完
有偿技术支持加微信