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;
}
The real decrypted value must be like this:
question from:
https://stackoverflow.com/questions/66045378/node-forge-decrypt-aes-256-cbc-shows-ilegible-characters 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…