gpt4 book ai didi

node.js - NodeJS 解密 des3 Unicode

转载 作者:太空宇宙 更新时间:2023-11-03 23:33:47 25 4
gpt4 key购买 nike

我有以下代码片段

var crypto = require("crypto");
var iv = new Buffer('d146ec4ce3f955cb', "hex");
var key = new Buffer('dc5c3319dc25c1f6f11f6a792a6dd28864c9dd48be26c2e4', "hex");
var encrypted = new Buffer('6A57201D19B07ABFAE74B453BA46381C', "hex");

var cipher = crypto.createDecipheriv('des3', key, iv);
var result = cipher.update(encrypted);
result += cipher.final();

console.log("result: " + result);

结果是“密码”此代码片段非常适合基于 ASCII 的单词。不过,我有一些 unicode 密码。

例如,这是 Pi:

UU__3185CDAA15C1CDED

我尝试过使用这个值,加上删除“UU__”,但没有收获。我还尝试了类似的加密数据:

var encrypted = new Buffer('UU__3185CDAA15C1CDED', "utf16le");

var result = cipher.update(encrypted, 'ucs2');

但没去..我收到以下错误

Error: error:06065064:digital envelope routines:EVP_DecryptFinal_ex:bad decr   ypt
at Error (native)
at Decipheriv.Cipher.final (crypto.js:202:26)
at Object.<anonymous> (/Users/miker/Local Projects/rec10_decryption/server2.js:14:18)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Function.Module.runMain (module.js:501:10)
at startup (node.js:129:16)
at node.js:814:3

任何帮助将不胜感激。

最佳答案

删除 UU_ 前缀并使用此代码对我有用:

var crypto = require('crypto');
var iv = new Buffer('d146ec4ce3f955cb', 'hex');
var key = new Buffer('dc5c3319dc25c1f6f11f6a792a6dd28864c9dd48be26c2e4', 'hex');
var encrypted = new Buffer('3185CDAA15C1CDED', 'hex');

var cipher = crypto.createDecipheriv('des3', key, iv);
var result = Buffer.concat([
cipher.update(encrypted),
cipher.final()
]).toString('ucs2');

console.log('result: ' + result);
// outputs: result: Π

当您执行 result += cipher.final() 时,它首先将 result 从 Buffer 转换为 (utf8) 字符串,然后附加 cipher .final() 从 Buffer 转换为 (utf8) 字符串。当您具有多字节字符时,如果您的字符字节跨度调用 .update().final(),则可能会导致数据损坏。将它们保留为缓冲区,将它们连接为二进制,然后将最终连接结果转换为 utf16 字符串将有效,并且更安全。

关于node.js - NodeJS 解密 des3 Unicode,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35108736/

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