我正在尝试使用CryptoJS进行解密,并在PyCrypto中进行加密。
我看到了这个出色的答案,它运作得很好,唯一的问题是它调整了PyCrypto以适应CryptoJS,我更喜欢定义输入规则并尽可能少地调整PyCrypto与其默认值。
我想提出请求:发送iv和使用零填充。
我在JS(ES6)中编写了以下内容:
然而,我遇到了ValueError错误:
如果我尝试通过
我看到了这个出色的答案,它运作得很好,唯一的问题是它调整了PyCrypto以适应CryptoJS,我更喜欢定义输入规则并尽可能少地调整PyCrypto与其默认值。
我想提出请求:发送iv和使用零填充。
我在JS(ES6)中编写了以下内容:
const iv = CryptoJS.enc.Hex.parse("1234567889012345");
const key = 'aR1h7EefwlPNVkvTHwfs6w=='
const encrypted = AES.encrypt(
password,
key,
{
iv,
padding: CryptoJS.pad.NoPadding
}
);
const payload = {password: encrypted, iv: iv};
// make HTTPS POST call
Python:
def decrypt_from_cryptoJS(encrypted, iv):
key = "aR1h7EefwlPNVkvTHwfs6w==".encode()
aes = AES.new(key.encode(), AES.MODE_CBC, iv)
encrypted = aes.decrypt(base64.b64decode(encrypted)))
然而,我遇到了ValueError错误:
raise TypeError("对象类型%s无法传递给C代码"%type(data))
。如果我尝试通过
CryptoJS.lib.WordArray.random(16)
创建VI,并通过JS的toString()方法发送它,则会得到以下结果:Incorrect IV length (it must be 16 bytes long)
用于启动AES
我如何在CryptoJS中进行解密,最小化在PyCrypto中的代码调整? 我不确定我是否走上了正确的道路..