Skip to content
Related Articles

Related Articles

Node.js crypto.verify() Function

Improve Article
Save Article
  • Last Updated : 24 Sep, 2021
Improve Article
Save Article

The crypto.verify()  is a method of the inbuilt module of node.js crypto that is used to verify the signature of data that is hashed using a different kind of hashing functions Like SHA256 algorithm etc.


crypto.verify(algorithm, data, publicKey, signature)


  • algorithm:  It is a string-type value. A signature can be verified by applying the name of signature algorithms, like ‘SHA256’. The algorithm must be the same in which the signature was created.
  • data: The data argument must be an instance of the buffer,  Typed Array, or Data View.
  • key: It should be the public key of the key object. If you have not any public key then you can create private and public keys using crypto.generateKeyPairSync() method.
  • signature: The signature argument must be an instance of Buffer, Typed Array, or Data View.

Returned value: This function returns a boolean value. Return True if a signature is verified else false.


Filename: index.js


// Importing Required Modules
const crypto = require('crypto');
const buffer = require('buffer');
// Creating a private key
const { privateKey, publicKey } = crypto.generateKeyPairSync('rsa', {
  modulusLength: 2048,
// Using Hashing Algorithm
const algorithm = "SHA256";
// Converting string to buffer
const data = Buffer.from("I Love GeeksForGeeks");
// Sign the data and returned signature in buffer
const signature = crypto.sign(algorithm, data , privateKey);
// Verifying signature using crypto.verify() function
const isVerified = crypto.verify(algorithm, data, publicKey, signature);
// Printing the result
console.log(`Is signature verified: ${isVerified}`);

Run index.js using the below command:

node index.js




My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!