aes加密

js下载地址:https://github.com/evanvosberg/crypto-js
客户端:
<script src="./src/core.js"></script>
<script src="./src/enc-base64.js"></script>
<script src="./src/md5.js"></script>
<script src="./src/cipher-core.js"></script>
<script src="./src/pad-zeropadding.js"></script>
<script src="./src/aes.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("abcd1234567890", key, { iv: iv,mode:CryptoJS.mode.CBC,padding:CryptoJS.pad.ZeroPadding});
document.write("encode:"+encrypted);
</script>

php服务端:
$text = "Message";
$key = md5($text); //key的长度必须16,32位,这里直接MD5一个长度为32位的key
$iv='1234567812345678';
//$crypttext = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $text, MCRYPT_MODE_CBC, $iv);
//var_dump(base64_encode($crypttext));
$crypttext = base64_decode('JtChGnqjPCCXTclGCYHsag==');
$decode = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $key, $crypttext, MCRYPT_MODE_CBC, $iv);
//echo base64_encode($crypttext);
//echo "<br/>";
echo $decode."\n";
//echo "<br/>";

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