字符串在这里用 php 加密。可以使用以下参数对其进行解密:Rijndael-256、ECB 和 Base64。但它不能被我的 ActionScript 代码解密:
var text:String = "Some data";
var key:ByteArray = new ByteArray();
key.writeUTFBytes("SomePassword");
key.position = key.length;
for (var i:int = key.length; i < 256 / 8; i++) {
key.writeByte(0);
}
var pad:IPad = new NullPad();
var cipher:ICipher = Crypto.getCipher("aes-256-ecb", key, pad);
var data:ByteArray = Base64.decodeToByteArray(text);
cipher.decrypt(data);
trace(data.toString());
升级版:
“无法解密”意味着我得到了错误的纯文本。
在 php 中,纯文本首先由 aes-256-ecb 加密。然后用Base64编码。在 ActionScript 中,这些步骤以相反的顺序完成。
UPD2:
测试编码解码:
var key:ByteArray = new ByteArray();
key.writeUTFBytes("Some password");
key.position = key.length;
for (var i:int = key.length; i < 256 / 8; i++) {
key.writeByte(0);
}
trace(key.toString());
var data:ByteArray = new ByteArray();//plain text
data.writeUTFBytes("Hello, my dear World! Hello, the Sun! Hello, the Moon! Hello! Hello! Hello!");
var pad:IPad = new NullPad();
var cipher:ICipher = Crypto.getCipher("aes-256-ecb", key, pad);
trace(data.toString());//trace plain text
cipher.encrypt(data);
trace(data.toString());//trace encrypted text
cipher.decrypt(data);
trace(data.toString());//trace decrypted text
停止后的输出cihper.encrypt(data)
为:
Some password
Hello, my dear World! Hello, the Sun! Hello, the Moon! Hello! Hello! Hello!
[Fault] exception, information=Error: Error #2030: End of file found.
UPD3:
它适用于 PKCS5 填充:
var pad:IPad = new PKCS5();
var cipher:ICipher = Crypto.getCipher("aes-256-ecb", key, pad);
pad.setBlockSize(cipher.getBlockSize());
输出是:
Some password
Hello, my dear World! Hello, the Sun! Hello, the Moon! Hello! Hello! Hello!
$ú^{±àÙ[pm|x¿9¡ÃZsI D¾`©4¾þÂõ,J
('èfÑk1ôì&ªQƆfbÇåòþ§VµÄs ¦p<iÿ
Hello, my dear World! Hello, the Sun! Hello, the Moon! Hello! Hello! Hello!
UPD4:
对于从 php (as here ) 获取的数据,带有 PKCS5 填充的代码在此处停止运行。并且使用 Null 填充它不会停止但解密的数据是错误的。