Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
380 views
in Technique[技术] by (71.8m points)

javascript - Node-forge decrypt aes-256-cbc shows ilegible characters

Hi I have this code in node-forge. When I run this code, the decrypted data is "ilegible".

const keyHash = "d0f95d5e54a7aa25934a5d4915c9e2a06dadac20d16551693be1d21d4d8e8798"
//This keyHash really is in utf8: Nootric2703202 hash(sha256)

const encryptedB64 = "U2FsdGVkX1++7PN6CsF5Bi38t0N3EjXpH5oGpaIZXUwk4T8QCwcATjvA4b/8VaxD8nf/MZhKPnWb1L8raLR4lw==";

var encrypted = Buffer.from(encryptedB64, 'base64');

var key = Buffer.from(keyHash, 'hex');
var res = forgeDecrypt();



function forgeDecrypt() {
    const encoding = 'utf8';
    key = key.toString(encoding);
    initVal = encrypted.toString(encoding).substring(0, 16);
    encrypted = encrypted.toString(encoding).substring(16);
    var decipher = forge.cipher.createDecipher('AES-CBC', key);
    decipher.start({ iv: initVal });
    decipher.update(forge.util.createBuffer(encrypted));
    var result = decipher.finish();
    result = decipher.output.getBytes();
    return result;
 }

enter image description here

The real decrypted value must be like this:

enter image description here

question from:https://stackoverflow.com/questions/66045378/node-forge-decrypt-aes-256-cbc-shows-ilegible-characters

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...