【发布时间】:2018-09-05 09:12:20
【问题描述】:
我正在尝试解密使用“crypto-js”编码的字符串,并使用“pyCrypto”在 python 中对其进行解码。我已经按照各种博客上的确切步骤进行操作,但仍然出现同样的错误。
我关注的最后一篇 stackoverflow 帖子是 “CryptoJS and Pycrypto working together”@Artjom B 给出的答案。
也试过“https://chase-seibert.github.io/blog/2016/01/29/cryptojs-pycrypto-ios-aes256.html”
我的js代码是
var pass = CryptoJS.AES.encrypt(text, password_encrypt_key,
{
iv: password_encrypt_iv,
})
return password_encrypt_iv.concat(pass.ciphertext).toString(CryptoJS.enc.Base64);
而我的python代码是
BLOCK_SIZE = 16
KEY = constants.PASSWORD_ENCRYPT_KEY
# IV = constants.PASSWORD_ENCRYPT_IV
IV = enc_password[:BLOCK_SIZE]
MODE = AES.MODE_CBC
enc_password = base64.b64decode(enc_password)
aes = AES.new(KEY, MODE, IV)
password = unpad(aes.decrypt(enc_password[BLOCK_SIZE:]))
取消填充功能
def unpad(s):
return s[:-ord(s[-1])]
【问题讨论】:
-
您的密钥长度必须正好为 16 个字节。
-
16 个字节为 16 个字符,是的,我已经尝试过了
标签: javascript python pycrypto cryptojs