Class: Sign
The Sign
Class is a utility for generating signatures. It can be used in one of two ways:
- As a writable stream, where data to be signed is written and the
sign.sign()
method is used to generate and return the signature, or - Using the
sign.update()
andsign.sign()
methods to produce 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 Sign
objects as streams:
const crypto = require('crypto'); const sign = crypto.createSign('RSA-SHA256'); sign.write('some data to sign'); sign.end(); const private_key = getPrivateKeySomehow(); console.log(sign.sign(private_key, 'hex')); // Prints the calculated signature
Example: Using the sign.update()
and sign.sign()
methods:
const crypto = require('crypto'); const sign = crypto.createSign('RSA-SHA256'); sign.update('some data to sign'); const private_key = getPrivateKeySomehow(); console.log(sign.sign(private_key, 'hex')); // Prints the calculated signature
Please login to continue.