我试图使用对称加密将数据从actionscript 3(客户端)传递到python(服务器)。Base64编码输出不同于as3crypto和pycrypto加密库
我使用的库是as3crypto和pycrypto,我不确定是否正确使用这些库。
的ActionScript 3:
private function testOnInit():void {
var t_toEnc:String = 'testtest';
var t_byAry:ByteArray = Hex.toArray(Hex.fromString(t_toEnc));
var t_key:ByteArray = Hex.toArray(Hex.fromString('Thisisthekey'));
var t_cbc:CBCMode = new CBCMode(new BlowFishKey(t_key), new NullPad);
var t_enc:String;
t_cbc.IV = Hex.toArray('30313233');
t_cbc.encrypt(t_byAry);
t_enc = Base64.encodeByteArray(t_byAry);
dbg('b64 encrypted string ' + t_enc); //this is just a debugging function we use in our code.
}
这是编码的函数的输出以上的base64。
xvVqLzV5TU4 =
现在,使用相同的密钥,初始化向量和算法从pycrypto库给了我不同的输出。
的Python:
from Crypto.Cipher import Blowfish
B = Blowfish.new('Thisisthekey', Blowfish.MODE_CBC, '30313233')
S = 'testtest'
X = B.encrypt(S)
import base64
Y = base64.b64encode(X)
print Y
I82NQEkSHhE =
我敢肯定,我做得不对的加密过程,因为我可以Base64编码 'TESTTEST' 在这两个库并接收相同的输出。
的ActionScript 3:
var b:ByteArray = new ByteArray();
b.writeUTFBytes('testtest');
dbg(Base64.encodeByteArray(b));
产量...
dGVzdHRlc3Q =
的Python:
>>> T = 'testtest'
>>> print base64.b64encode(T)
产量
dGVzdHRlc3Q =
可能有人请加密和用Python或动作相同IV base64encode相同的字符串,所以我知道该库实际上是产生正确的输出?
当您使用每个库来解密每个加密值时会发生什么? – 2011-01-12 20:25:46