gpt4 book ai didi

javascript - 密码破译错误

转载 作者:行者123 更新时间:2023-11-30 18:05:55 25 4
gpt4 key购买 nike

为什么以下代码会在加密中抛出 DecipherFinal 错误 -

  var crypto = require('crypto');
c=new Date;
x= (c.getTime()+"."+c.getMilliseconds()).toString()+".uIn";
key = 'sevsolut'
, plaintext = x
, cipher = crypto.createCipher('aes-256-cbc', key)
, decipher = crypto.createDecipher('aes-256-cbc', key);
cipher.update(plaintext, 'utf8', 'base64');
var encryptedPassword = cipher.final('base64')

decipher.update(encryptedPassword, 'base64', 'utf8');
var decryptedPassword = decipher.final('utf8');

console.log('encrypted :', encryptedPassword);
console.log('decrypted :', decryptedPassword);

最佳答案

您需要获取更新的输出:

var crypto = require('crypto');
c=new Date();
x= (c.getTime()+"."+c.getMilliseconds()).toString()+".uIn";
key = "sevsolut"
, plaintext = x
, cipher = crypto.createCipher('aes-256-cbc', key)
, decipher = crypto.createDecipher('aes-256-cbc', key);
var encryptedPassword = cipher.update(plaintext, 'utf8', 'base64');
encryptedPassword += cipher.final('base64')

var decryptedPassword = decipher.update(encryptedPassword, 'base64', 'utf8');
decryptedPassword += decipher.final('utf8');

console.log('encrypted :', encryptedPassword);
console.log('decrypted :', decryptedPassword);

关于javascript - 密码破译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15805975/

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