[JS]AES加密(基于crypto-js)PHP后端解密
这里主要讲 前端使用crypto-js AES加密后,php解密。
前端js
<script src="http://crypto-js.googlecode.com/svn/tags/3.0.2/build/rollups/aes.js"></script> <script src="http://crypto-js.googlecode.com/svn/tags/3.0.2/build/rollups/md5.js"></script> <script src="http://crypto-js.googlecode.com/svn/tags/3.0.2/build/components/pad-zeropadding.js"></script> <script> var key_hash = CryptoJS.MD5("Message"); var key = CryptoJS.enc.Utf8.parse(key_hash); var iv = CryptoJS.enc.Utf8.parse('1234567812345678'); var encrypted = CryptoJS.AES.encrypt("Message", key, { iv: iv,mode:CryptoJS.mode.CBC,padding:CryptoJS.pad.ZeroPadding}); document.write("encode:"+encrypted); </script>
php代码
<?php $text = "Message"; $key = md5($text); //CuPlayer.com提示key的长度必须16,32位,这里直接MD5一个长度为32位的key $iv='1234567812345678'; $crypttext = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $text, MCRYPT_MODE_CBC, $iv); $decode = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $key, $crypttext, MCRYPT_MODE_CBC, $iv); echo base64_encode($crypttext); echo "<br/>"; echo $decode; echo "<br/>"; ?>
相关推荐
JF0 2019-12-09
MXstudying 2019-07-01
puddingpp 2019-06-27
IT日志 2017-04-19
githubphpnobug 2016-10-26
tengyuan 2020-05-30
visionzheng 2020-05-04
LowisLucifer 2020-04-30
dbhllnr 2020-04-26
wordmhg 2020-03-27
wbingyang 2020-02-14
CloudXli 2020-01-12
ahnuzfm 2019-12-24
hgzhang 2019-10-22
数据与算法之美 2015-03-09
frankwtq 2012-02-02
guohewei 2019-03-28