问题描述
所以我一直试图在 python 中解密最初在 node.js 应用程序中加密的数据,但显然没有成功。 Node.js 代码是:
encrypt(text) {
const cipher = crypto.createCipher(algorithm,secret);
let crypted = cipher.update(text,'utf8','hex');
crypted += cipher.final('hex');
return crypted;
},
这里的“秘密”变量是:“MyUltraSecurePassWordIWontForgettochange”
算法是:'aes-256-ecb'
现在,我可以生成一段加密的文本,但无法在 python 中以某种方式解密它。我在 Stackoverflow 上查找了解决方案,例如:
encrypted = "267e6a9d5a128fb1f44e670fcd89793af50fa9a831e6ae7dc2f0592b508bd224a71290fbdf1619cf52ed0f2c034b263861443b6e7ed2966c886f9ab610f1b1abccd9054b80720bbaaf9dc5d3ff57d28678118da17132df3c0c78faf75aa038bfd9d027aa7c6c47e10fd86a4f75aa8d6ca118af7c29e8fe485676bdf377a7bc3a5322127fb22daed153db078cb91239d3e1984d06dea920b5d193d389d51e6b92106dae6e518554e05f8d0a7aaa46d47e1657bede22961c248bcb16985c96ad5100ebce440903af962314610247b39bfc" # Example
# Generate key and iv
keySize = 16
ivSize = 16
digest = hashlib.md5
salt = b''
password = b'MyUltraSecurePassWordIWontForgettochange' # Example
iteration = 1
keyiv = EVP_BytesToKey(keySize,ivSize,digest,salt,password,iteration)
key = keyiv[0]
iv = keyiv[1]
# Define counter
nbits = 128
initial_value = int.from_bytes(iv,byteorder = 'big');
counter = Counter.new(nbits,initial_value = initial_value)
# Decrypt
cipher = AES.new(key,AES.MODE_CTR,counter = counter)
decrypted = cipher.decrypt(bytes.fromhex(encrypted))
print("Decrypted: " + decrypted.decode('utf-8'))
这给了我错误:“UnicodeDecodeError:‘utf-8’编解码器无法解码位置 3 中的字节 0xc0:起始字节无效”
如果有人能指导我朝着正确的方向前进,我将不胜感激。谢谢和问候
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)