From 895a9299255525cb57886deb9d9fd4ba17ae9548 Mon Sep 17 00:00:00 2001 From: n1474335 Date: Wed, 23 Oct 2024 14:03:09 +0100 Subject: [PATCH] Fixed RSA Sign and Verify character encodings --- src/core/operations/RSASign.mjs | 2 +- src/core/operations/RSAVerify.mjs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/operations/RSASign.mjs b/src/core/operations/RSASign.mjs index 25160f53..5091549f 100644 --- a/src/core/operations/RSASign.mjs +++ b/src/core/operations/RSASign.mjs @@ -60,7 +60,7 @@ class RSASign extends Operation { const privateKey = forge.pki.decryptRsaPrivateKey(key, password); // Generate message hash const md = MD_ALGORITHMS[mdAlgo].create(); - md.update(input, "utf8"); + md.update(input, "raw"); // Sign message hash const sig = privateKey.sign(md); return sig; diff --git a/src/core/operations/RSAVerify.mjs b/src/core/operations/RSAVerify.mjs index 89b7d81f..11dc0fb4 100644 --- a/src/core/operations/RSAVerify.mjs +++ b/src/core/operations/RSAVerify.mjs @@ -60,7 +60,7 @@ class RSAVerify extends Operation { const pubKey = forge.pki.publicKeyFromPem(pemKey); // Generate message digest const md = MD_ALGORITHMS[mdAlgo].create(); - md.update(message, "utf8"); + md.update(message, "raw"); // Compare signed message digest and generated message digest const result = pubKey.verify(md.digest().bytes(), input); return result ? "Verified OK" : "Verification Failure";