Skip to content

Conversation

@jrrbru
Copy link

@jrrbru jrrbru commented Aug 16, 2014

As part of an effort to use this library to do signature generation and verification, I added two new internal methods to jsencrypt.js:

RSASign(text, hashMethod, padMethod)
RSAVerify(signature, text, hashMethod, unPadMethod)

These are exposed via JSEncrypt.sign(...) and JSEncrypt.verify(...). These two methods allow you to sign and verify text, while supplying your own hashMethod and padMethod. This allows you to support any hash method and padding scheme for interoperability with server-side code:

// Create the encryption object.
crypt = new JSEncrypt();

// Set the public key
crypt.setPublicKey('-----BEGIN PUBLIC KEY-----.....-----END PUBLIC KEY-----');

// verify the signature
if (crypt.verify(signature, terms_string, Hashes.SHA256.hex, myUnPaddingMethod)) {
    // do stuff here
}

Also included are a few JSDoc changes that more accurately reflect the types returned from various functions (like changing @returns {string} to @returns {string|boolean} when one possible execution path returns false).

@zoloft
Copy link
Collaborator

zoloft commented Aug 18, 2014

Looks good to me, could you please add some test cases?

@travist
Copy link
Owner

travist commented Feb 17, 2018

Please rebase against master using TypeScript and I will accept this PR.

@milaabl
Copy link

milaabl commented Jan 7, 2023

@travist , are you still interested in this function?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants