CryptoJS加密此中iv为32位,php 解密

WBOY
Release: 2016-06-13 12:17:33
Original
2007 people have browsed it

CryptoJS加密其中iv为32位,php 解密

<br /><script type="text/javascript" src='aes.js'></script><br />	<script type="text/javascript"><br />	    var key = '123454536f667445454d537973576562';<br />	    key = CryptoJS.enc.Hex.parse(key);<br />		var iv = CryptoJS.enc.Hex.parse("1234577290ABCDEF1264147890ACAE45");<br />		var encrypted = CryptoJS.AES.encrypt('T10515', key, {iv: iv,mode:CryptoJS.mode.CBC}).toString()<br />		alert(encrypted);<br />	</script><br />
Copy after login


js代码如上,现在想用php来加密
<br /><?php<br />$pk = "123454536f667445454d537973576562";<br />$iv = "1234577290ABCDEF1264147890ACAE45";<br />$t = ('T10515');<br /><br />$encrypted = ( mcrypt_encrypt(MCRYPT_RIJNDAEL_128,$pk,$t,MCRYPT_MODE_CBC,$iv) );<br />echo 'base64_encode'.(base64_encode($encrypted)).'<br>';<br />?><br />
Copy after login

为什么不行?出现警告如下:
<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<br />
Copy after login


我知道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 是得不到的

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template