Skip to content

Conversation

@Spark-NF
Copy link
Contributor

@Spark-NF Spark-NF commented May 24, 2018

Two methods were added to the JSEncrypt class:

  • sign, which takes a string to sign, a hash method, as well as the name of the hash method
  • verify, which takes a string to verify, its signature, and a hash method

The name of the hash method is required because RSA signatures need a header depending on which hash was used (see https://tools.ietf.org/html/rfc3447#page-43).

I tested that generated signatures can be verified by JSEncrypt, jsrsasign, and SubtleCrypto with no issues. It can verify signatures from JSEncrypt, jsrsasign, and SubtleCrypto also.

Fixes issue #2.

Signing example

var data = "some data";
var jse = new JSEncrypt();
jse.setPrivateKey(privateKey);
var signature = jse.sign(data, CryptoJS.SHA256, "sha256");

Verifying example

var data = "some data";
var jse = new JSEncrypt();
jse.setPublicKey(publicKey);
if (jse.verify(data, signature, CryptoJS.SHA256)) {
    console.log("Valid signature.");
}

@harpcio
Copy link

harpcio commented Jun 22, 2018

+1

@travist
Copy link
Owner

travist commented Jun 25, 2018

Well done.

@travist travist merged commit 95c69f2 into travist:master Jun 25, 2018
@travist
Copy link
Owner

travist commented Jun 25, 2018

Do you mind adding some docs to the Readme.md file for this?

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.

3 participants