gpt4 book ai didi

javascript 'hex' 未知行为

转载 作者:行者123 更新时间:2023-11-30 00:25:41 24 4
gpt4 key购买 nike

在尝试将十六进制值传递给 Node js 中的加密密码时,我在密文上得到空白返回,而在 ciphertext2 上得到正确返回。无法解释这两种情况之间的区别。

var secret = 'YmcNFa37DrT+0p10pnSpQSytWxlqNCyU';
var cipher = crypto.createCipher('des3', secret);
var plaintext = '3b9ac9ff';
var ciphertext = cipher.update(plaintext, 'hex', 'hex');
var ciphertext2 = cipher.update('3b9ac9ff', 'hex', 'hex');
console.log(plaintext + ' , ' +ciphertext + ' , '+ ciphertext2);

给我一​​个输出

3b9ac9ff ,  , 0472620ba5ddf690

最佳答案

发现问题。由@Andreas 指出。

var ciphertext = cipher.update(plaintext, 'hex', 'hex');

应该是

var ciphertext = cipher.update(plaintext, 'ascii', 'hex');

导致困惑的两个原因(虽然没有理由愚蠢)1. Node js不会给你运行时异常。相反,就像上面指出的那样表现得很糟糕。2. 允许输出为十六进制,这让我相信甚至允许输入。

关于javascript 'hex' 未知行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31532386/

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