Verify

Class: Verify

The Verify class is a utility for verifying signatures. It can be used in one of two ways:

  • As a writable stream where written data is used to validate against the supplied signature, or
  • Using the verify.update() and verify.verify() methods to verify the signature.

    The crypto.createSign() method is used to create Sign instances. Sign objects are not to be created directly using the new keyword.

Example: Using Verify objects as streams:

const crypto = require('crypto');
const verify = crypto.createVerify('RSA-SHA256');

verify.write('some data to sign');
verify.end();

const public_key = getPublicKeySomehow();
const signature = getSignatureToVerify();
console.log(sign.verify(public_key, signature));
  // Prints true or false

Example: Using the verify.update() and verify.verify() methods:

const crypto = require('crypto');
const verify = crypto.createVerify('RSA-SHA256');

verify.update('some data to sign');

const public_key = getPublicKeySomehow();
const signature = getSignatureToVerify();
console.log(verify.verify(public_key, signature));
  // Prints true or false
doc_Nodejs
2016-04-30 04:43:09
Comments
Leave a Comment

Please login to continue.