Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add verifying raw signature #353

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/rsasign-1.2.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,26 @@ function _rsasign_getAlgNameAndHashFromHexDisgestInfo(hDigestInfo) {
return [];
}

/**
* verifies a raw RSA sigature for a message string with RSA public key.<br/>
* @name verifyRawWithMessageHex
* @memberOf RSAKey#
* @function
* @param {String} sMsgHex hexadecimal string of message to be verified.
* @param {String} hSig hexadecimal string of raw siganture.<br/>
* 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.<br/>
* @name verify
Expand Down