16字符长度的 iv 和32字符长度的 key 怎么在 nodejs 用 aes-128-cbc

用网上提供的方法总是报错:Invalid key length
有什么办法吗?

const hash = '56e71d68a230081a0fe562ae4daaf58451db4ce4bde4f881b65b713cc8c3248405a3a2c8520cb8a7215f9ebaa604dae62d320f2c77bda679a2d3df1ecc790ee5a7113afe6974e5e89d2a10d0e63a2b5cbe05923fe6765f0eca1ddea969e4fe39b1d951554b0dfe66aafd4b24bd138d848c479186ed13139328b37e34200ecd4a718b7f3f268fdc6d1a174a192c8d1150a8c56686783f19dbeaa7f03a943ce4089768655843311e5c3ac8ae05d0d5990723521e04dcb5137e470c20990365f742ae78492178cb2d512cb7cb55d229218dc66f1f5234e3546cca534d3e8787dfb6b720c069dbb9a344d944d22aaf01e921'

const iv = 'e6db271db12d4d47'

const key = '9cd5b4cf899492077b4a125a79af8e76'

const crypto = require('crypto')


 const aesDecrypt = function(data, secretKey, iv) {

   const cipherEncoding = 'base64'

   const clearEncoding = 'utf8'

   const cipher = crypto.createDecipheriv('aes-128-cbc',secretKey, iv)

   return cipher.update(data,cipherEncoding,clearEncoding) + cipher.final(clearEncoding)

 }


console.log(aesDecrypt(hash, key, iv))


达令说
浏览 1694回答 1
1回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript