我试图将一些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 ......还是字符串?
到目前为止,这是我的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
的任何见解。
谢谢!
答案 0 :(得分:1)