首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >节点JS -加密/解密

节点JS -加密/解密
EN

Stack Overflow用户
提问于 2021-03-16 08:54:11
回答 1查看 45关注 0票数 0

我有一个这样的加密函数

代码语言:javascript
复制
const encryptWithInitVector = (string, keyBase64, ivBase64) => {
  const key = Buffer.from(keyBase64, 'base64')
  const iv = Buffer.from(ivBase64, 'base64')

  const cipher = crypto.createCipheriv(getAlgorithm(keyBase64), key, iv)
  let encrypted = cipher.update(string, 'utf8', 'base64')
  encrypted += cipher.final('base64')
  return encrypted
}

它接收要编码的字符串、AESKey和initializationVector。

如何创建相反的路径?我想解码函数encryptWithInitVector的响应

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-03-16 09:16:12

https://nodejs.org/api/crypto.html#crypto_crypto_createdecipheriv_algorithm_key_iv_options

使用crypto.createDecipheriv创建解密

代码语言:javascript
复制
const decryptWithInitVector = (string, keyBase64, ivBase64) => {
  const key = Buffer.from(keyBase64, 'base64')
  const iv = Buffer.from(ivBase64, 'base64')

  const decipher = crypto.createDecipheriv(getAlgorithm(keyBase64), key, iv)

  let decrypted = decipher.update(string,'base64','utf-8');
  decrypted += decipher.final('utf-8');
  return decrypted
}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66647688

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档