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

added support for RSA signatures. #16

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

Conversation

khatribharat
Copy link

I've added support for RSA signatures.

Usage :

/* sign */ 
var signatory = new JSEncrypt();
var privateKey = "RSA_PRIVATE_KEY";
signatory.setPrivateKey(privateKey);
var message = "I'm a message, sign me !";
var rsa_sha256_signature = signatory.sign(message, CryptoJS.SHA256);

/* verify */
var verifier = new JSEncrypt();
var publicKey = "RSA_PUBLIC_KEY";
verifier.setPublicKey(publicKey);
if (verifier.verify(message, rsa_sha256_signature, CryptoJS.SHA256)) {
 console.log("valid signature !");
}

@travist
Copy link
Owner

travist commented Dec 27, 2013

Thank you for your contribution. I think I can accept this once myself and maybe some other people have time to test it and verify that it works as it should. There are a few things that need to be fixed with regard to coding standards, but I will put those in other comments.

return digest == digestMethod(text);
}

RSAKey.prototype.verify = RSAVerify;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just assign the function directly instead of having a separate function? Something like this?

RSAKey.prototype.verify = function(text, signature, digestMethod) {
  var c = parseBigInt(signature, 16);
  var m = c.modPowInt(this.e, this.n);
  if (m == null) return null;
  var digest = pkcs1unpad2(m, (this.n.bitLength()+7)>>3);
  console.log("RSAVerify: message digest :- " + digest);
  return digest == digestMethod(text);
};

Same goes for the other function you created.

@bramski
Copy link

bramski commented Jun 26, 2014

+1 ?

@alecdotninja
Copy link

+1

@walmon
Copy link

walmon commented Aug 12, 2015

You example is always returning false

@cmcg513
Copy link

cmcg513 commented Apr 28, 2016

+1

@briantbutton
Copy link

-er- any way I could help to get this updated and merged? Really need the signing feature.

@hazcod
Copy link

hazcod commented Feb 24, 2017

@khatribharat Any chance you could fix those conflicts?

@travist
Copy link
Owner

travist commented Feb 17, 2018

Please rebase against master using TypeScript.

@Spark-NF Spark-NF mentioned this pull request May 24, 2018
@tianyingchun
Copy link

the digest method CryptoJS.SHA256 is npm module crypto-js? i see the test case it use customized digestmethod

const digest = (data: string): string => {
        return data;
      };

it works fine, if we use md5, 'sha256`, it always return false. it's a bug?

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.

9 participants