gpt4 book ai didi

node.js - 使用 NodeJs createDecipheriv 解密密文。我究竟做错了什么?

转载 作者:搜寻专家 更新时间:2023-10-31 22:36:47 25 4
gpt4 key购买 nike

我有以下代码可以解密加密文本:

var crypto = require('crypto');
var Buffer = require('buffer').Buffer;

var iv = new Buffer('the-iv', 'binary'); //length=16
var key = new Buffer('the-secret-key', 'binary');//length=30

var encryptedText = new Buffer('base64-encoded-encrypted-data', 'base64');

var decipher = crypto.createDecipheriv('aes-128-cbc', key, iv); //using the aes-128-cbc algorithm
decrypted = decipher.update(encryptedText, "binary", 'utf8');
decrypted += decipher.final('utf8');

当我执行脚本 node test-main.js 时,出现以下错误:

node-crypto : Invalid key length 30

crypto.js:355
this._binding.initiv(cipher, toBuf(key), toBuf(iv));
^
Error: DecipherInitIv error
at new Decipheriv (crypto.js:355:17)
at Object.Decipheriv (crypto.js:352:12)
at Object.<anonymous> (path/to/file/test-main.js:9:19)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:901:3

我的NodeJs版本是0.10.15

我不确定我做错了什么/遗漏了什么。

最佳答案

请尝试使用长度为 16 的 key 。aes-128-cbc 使用 128 位 key 。

关于node.js - 使用 NodeJs createDecipheriv 解密密文。我究竟做错了什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17974846/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com