我正在尝试将一些Python代码移植到Javascript。以下是Python代码:
# Python
import codecs
from Crypto.Cipher import AES
key = b"\xc3\x99\xff\xff\xc3\x99\xff\xff\xc3\x99\xff\xff\xc3\x99\xff\xff"
...
aes = AES.new(key, AES.MODE_ECB)
token = aes.encrypt("HELLO\x00\x00".encode("utf-8"))
token_hex = codecs.encode(token, "hex").decode("utf-8")我不太确定如何移植我的Python key变量。应该是UInt16Array...or a string吗?
这是到目前为止我的Javascript:
// Javascript
const crypto = require('crypto');
const key = '???' // <-- This is one place I am stuck. String? Byte array?
....
const cipher = crypto.createCipher('aes-128-ecb', key);
let tokenHex = cipher.update('HELLO\x00\x00', 'utf8', 'hex');
tokenHex = tokenHex.toString('utf8')我很感谢你能提供的关于如何在Javascript中获得匹配的tokenHex的见解。
谢谢!
发布于 2018-01-16 04:08:55
https://stackoverflow.com/questions/48269945
复制相似问题