From b1fcfeaa31a620d507f77369267fd420c2c6bbe9 Mon Sep 17 00:00:00 2001 From: Saurav Sachidanand Date: Sat, 19 May 2018 18:17:29 +0530 Subject: [PATCH] Add verifying raw signature --- src/rsasign-1.2.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/rsasign-1.2.js b/src/rsasign-1.2.js index 4fb2b0cb..4f0b9d08 100644 --- a/src/rsasign-1.2.js +++ b/src/rsasign-1.2.js @@ -221,6 +221,26 @@ function _rsasign_getAlgNameAndHashFromHexDisgestInfo(hDigestInfo) { return []; } +/** + * verifies a raw RSA sigature for a message string with RSA public key.
+ * @name verifyRawWithMessageHex + * @memberOf RSAKey# + * @function + * @param {String} sMsgHex hexadecimal string of message to be verified. + * @param {String} hSig hexadecimal string of raw siganture.
+ * non-hexadecimal charactors including new lines will be ignored. + * @return returns 1 if valid, otherwise 0 + */ +RSAKey.prototype.verifyRawWithMessageHex = function(sMsgHex, hSig) { + hSig = hSig.replace(_RE_HEXDECONLY, ''); + hSig = hSig.replace(/[ \n]+/g, ""); + var biSig = parseBigInt(hSig, 16); + if (biSig.bitLength() > this.n.bitLength()) return 0; + var biDecryptedSig = this.doPublic(biSig); + var hMsgHex = biDecryptedSig.toString(16).replace(/^1f+00/, ''); + return (hMsgHex == sMsgHex); +}; + /** * verifies a sigature for a message string with RSA public key.
* @name verify