From 47c85a105ddbdd4cabfa44ddddbc56e3907a8c33 Mon Sep 17 00:00:00 2001 From: n1474335 Date: Wed, 23 Oct 2024 16:02:08 +0100 Subject: [PATCH] Added message format arg to RSA Verify operation --- src/core/operations/RSAVerify.mjs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/core/operations/RSAVerify.mjs b/src/core/operations/RSAVerify.mjs index 11dc0fb4..8160438c 100644 --- a/src/core/operations/RSAVerify.mjs +++ b/src/core/operations/RSAVerify.mjs @@ -8,6 +8,7 @@ import Operation from "../Operation.mjs"; import OperationError from "../errors/OperationError.mjs"; import forge from "node-forge"; import { MD_ALGORITHMS } from "../lib/RSA.mjs"; +import Utils from "../Utils.mjs"; /** * RSA Verify operation @@ -37,6 +38,11 @@ class RSAVerify extends Operation { type: "text", value: "" }, + { + name: "Message format", + type: "option", + value: ["Raw", "Hex", "Base64"] + }, { name: "Message Digest Algorithm", type: "option", @@ -51,7 +57,7 @@ class RSAVerify extends Operation { * @returns {string} */ run(input, args) { - const [pemKey, message, mdAlgo] = args; + const [pemKey, message, format, mdAlgo] = args; if (pemKey.replace("-----BEGIN RSA PUBLIC KEY-----", "").length === 0) { throw new OperationError("Please enter a public key."); } @@ -60,7 +66,8 @@ class RSAVerify extends Operation { const pubKey = forge.pki.publicKeyFromPem(pemKey); // Generate message digest const md = MD_ALGORITHMS[mdAlgo].create(); - md.update(message, "raw"); + const messageStr = Utils.convertToByteString(message, format); + md.update(messageStr, "raw"); // Compare signed message digest and generated message digest const result = pubKey.verify(md.digest().bytes(), input); return result ? "Verified OK" : "Verification Failure";