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

Support RSA signing with custom padding #29

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

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