<script type="text/javascript" src='aes.js'></script>
<script type="text/javascript">
var key = '123454536f667445454d537973576562';
key = CryptoJS.enc.Hex.parse(key);
var iv = CryptoJS.enc.Hex.parse("1234577290ABCDEF1264147890ACAE45");
var encrypted = CryptoJS.AES.encrypt('T10515', key, {iv: iv,mode:CryptoJS.mode.CBC}).toString()
alert(encrypted);
</script>
js代码如上,现在想用php来加密
<?php
$pk = "123454536f667445454d537973576562";
$iv = "1234577290ABCDEF1264147890ACAE45";
$t = ('T10515');
$encrypted = ( mcrypt_encrypt(MCRYPT_RIJNDAEL_128,$pk,$t,MCRYPT_MODE_CBC,$iv) );
echo 'base64_encode'.(base64_encode($encrypted)).'<br>';
?>
为什么不行?出现警告如下:
Warning: mcrypt_encrypt(): Received initialization vector of size 32, but size 16 is required for this encryption mode in F:\LAMP\Apache2.4\htdocs\fee\cry.php on line 32
我知道js那里CryptoJS.enc.Hex.parse是转16进制的,但是这串字符串不已经是16进制了吗?
------解决思路----------------------
$pk = pack('H*', "123454536f667445454d537973576562");
$iv = pack('H*', "1234577290ABCDEF1264147890ACAE45");
W/3ax9dAw/GQ/ELf5enWeQ==
T10515
W/3ax9dAw/GQ/ELf5enWeQ==
T10515
如果你坚持不加 padding:CryptoJS.pad.ZeroPadding(不足部分以'\0'充填)的话,那就是无解了
dRewstG3hsVzDdKJxzmXtg==
这样的结果,php 是得不到的