我正在为我的node.js项目集成一个支付网关。他们在python中有集成工具包,而我在这方面没有多少经验。我将他们的更改从python移植到javascript。这是对的吗?
Python代码:
def encrypt(plainText,workingKey):
iv = 'hello'
encDigest = md5.new ()
encDigest.update(workingKey)
enc_cipher = AES.new(encDigest.digest(), AES.MODE_CBC, iv)
encryptedText = enc_cipher.encrypt(plainText).encode('hex')
return encryptedText移植代码(Node.js):
function encrypt(plainText, workingKey){
var iv = 'hello';
var encDigest = crypto.createHash('md5');
encDigest.update(workingKey);
var enc_cipher = crypto.createCipheriv('aes-256-cbc', encDigest, iv);
var encryptedText = enc_cipher.encrypt(plainText).encode('hex');
return encryptedText;
}发布于 2015-12-27 04:47:02
不管用吗?我能看到的唯一可能的问题是异步和同步。例如,当var encDigest = crypto.createHash('md5');被触发时,encDigest.update(workingKey);可能不会被解析。
https://stackoverflow.com/questions/23560116
复制相似问题