我想用 python ( aes-128-ecb
) 加密一个字符串,然后用 node.js 解密这个字符串。下面是我写的。我不知道为什么它不起作用。
PyCrypto 库文档:http://pythonhosted.org//pycrypto/
节点加密库文档:http ://nodejs.org/api/crypto.html
Python代码
from Crypto.Cipher import AES
import binascii
aes_key = '\x26\x33\x3B\x48\x28\x69\x77\x8C\x14\xA2\xBE\xC1\xD4\xE2\xFD\x14'
aes = AES.new(aes_key)
data = aes.encrypt('testtesttesttest')
print binascii.hexlify(bytearray(data))
# output >> 5cc4711e67703657f0a04d887d7c074e
JS代码
var crypto = require('crypto');
var aes_key = new Buffer('26333B482869778C14A2BEC1D4E2FD14', 'hex');
var data = new Buffer('b4364ee66c808b3b0f24070879a3b224', 'hex');
var aes = crypto.createDecipher('aes-128-ecb', aes_key);
aes.setAutoPadding(false);
var data = Buffer.concat([aes.update(data), aes.final()]);
console.log(data.toString());
// output >> X4b�1�5(��̣F<�f