Skip to content

Commit

Permalink
Merge pull request travist#127 from Spark-NF/master
Browse files Browse the repository at this point in the history
Add sign/verify doc to the README file
  • Loading branch information
travist authored Jun 28, 2018
2 parents cc8a8c7 + bd33597 commit ea32a51
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,31 @@ gwQco1KRMDSmXSMkDwIDAQAB

- Look at how http://www.travistidwell.com/jsencrypt/example.html works to get a better idea.

- Signing and verification works in a similar way.

```javascript
// Sign with the private key...
var sign = new JSEncrypt();
sign.setPrivateKey($('#privkey').val());
var signature = sign.sign($('#input').val(), CryptoJS.SHA256, "sha256");

// Verify with the public key...
var verify = new JSEncrypt();
verify.setPublicKey($('#pubkey').val());
var verified = verify.verify($('#input').val(), signature, CryptoJS.SHA256);

// Now a simple check to see if the round-trip worked.
if (verified) {
alert('It works!!!');
}
else {
alert('Something went wrong....');
}
```

- Note that you have to provide the hash function. In this example we use one from the [CryptoJS](https://github.com/brix/crypto-js) library, but you can use whichever you want.
- Also, unless you use a custom hash function, you should provide the hash type to the `sign` method. Possible values are: `md2`, `md5`, `sha1`, `sha224`, `sha256`, `sha384`, `sha512`, `ripemd160`.

Other Information
========================

Expand Down

0 comments on commit ea32a51

Please sign in to comment.