我正在尝试使用Crypto.js进行简单的加密,然后使用Node.js加密库进行解密。
const crypto = require('crypto')
const CryptoJS = require('crypto-js')
const message = 'Hello World'
const key = '3zTvzr3p67VC61jmV54rIYu1545x4TlY'
const iv = '655478daef95fdae'
const encrypted = CryptoJS.AES.encrypt(message, key, {
iv: iv,
padding: CryptoJS.pad.Pkcs7,
mode: CryptoJS.mode.CBC
})
const encryptedString = encrypted.toString()
const cipher = crypto.createDecipheriv('aes-256-cbc', key, iv)
let decrypted = cipher.update(encryptedString, 'base64', 'utf8')
decrypted += cipher.final('utf8')
console.log(decrypted)
对cipher.final('utf8')
的调用出现错误:
Error: error:06065064:digital envelope routines:EVP_DecryptFinal_ex:bad decrypt
据我所知,此错误与密钥错误有关,但我不知道这里的情况如何。