解密PHP中的as3crypto加密文本 [英] decrypt a as3crypto encrypted text in PHP
问题描述
我试图通过演示程序加密as3crypto中的文本。
i tried to encrypt a text in as3crypto via the demo app.
现在我试图通过php解密加密的文本,但似乎文本不是妥善解密。有谁知道如何通过PHP正确解密?还是我做错了?请启发我...
now i am trying to decrypt the crypted text via php but it seems that the text is not properly decrypted. has anyone know how to properly decrypt it via PHP? or am I doing it wrong? please enlighten me...
这里是这种情况:
-
在 http://crypto.hurlant.com/demo/ 中进行加密:
加密: AES
模式: CBC
padding: none
键: 11918f8bcd112e92744125008722050c
key: 11918f8bcd112e92744125008722050c
文字: Lorem ipsum dolor sit amet,consectetur adipiscing elit。
text: Lorem ipsum dolor sit amet, consectetur adipiscing elit. In ut massa nec purus laoreet posuere quis vitae tortor.
初始化向量: 将其留空
按加密。选择base64并复制密文。
press encrypt. select base64 and copy the cipher text.
制作一个具有这些代码并运行它的PHP脚本:
make a php script that has these codes and run it:
$ cipher = MCRYPT_RIJNDAEL_128;
$cipher = MCRYPT_RIJNDAEL_128;
$ mode = MCRYPT_MODE_CBC;
$mode = MCRYPT_MODE_CBC;
$ key =11918f8bcd112e92744125008722050c;
$key = "11918f8bcd112e92744125008722050c";
$ cipher =PLACE CIPHER TEXT HERE ...;
$cipher = "PLACE CIPHER TEXT HERE...";
$ data = base64_decode($ cipher);
$data = base64_decode($cipher);
echo mcrypt_decrypt($ cipher,$ key,$ data ,$ mode);
echo mcrypt_decrypt($cipher, $key, $data, $mode);
推荐答案
这个问题可能在于你的钥匙。虽然你可以将一个十六进制字符串提供给as3crypto,它会知道该怎么做, mcrypt_decrypt
会将每个字符解释为它的底层ASCII值(如a = 97),而不是它是十六进制值(a = 10)。使用 hex2bin 方法将十六进制字符串转换为字节字符串,并解密应该可以正常工作。
the issue probably lies in your key. While you can feed a hex string to as3crypto and it will know what do to with it, mcrypt_decrypt
will interpret each character as it's underlying ASCII value (like a = 97) instead of it's hexadecimal value (a = 10). Use the hex2bin method to convert the hex string into a byte string, and your decryption should probably work fine.
还有一个问题可能在于as3crypto和php之间的默认IV(初始化向量)的不同想法。既然你使用CBC模式,你应该指定一个IV,就像一个很好的安全实践。还要注意与您的密钥类似的潜在陷阱,在as3中指定十六进制字符串,需要在php中转换。
also, an issue may rest with different ideas of a default IV (initialization vector) between as3crypto and php. Since you are using CBC mode, you should be specifying an IV, just as a good security practice. also be aware of the potential pitfalls similar to those with your key, of specifying a hex string in as3 and needing to convert it in php.
这篇关于解密PHP中的as3crypto加密文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!