Open In App

Node.js crypto.webcrypto Property

Improve
Improve
Like Article
Like
Save
Share
Report

The crypto.webcrypto is an inbuilt application programming interface of class Crypto within crypto module which is used to get the object of crypto of Web Crypto API standard.

Syntax:

const crypto.webcrypto

Parameters: This property accepts nothing as parameter.

Return Value: This property returns the object of crypto of Web Crypto API standard.

Example 1:

index.js




// Node.js program to demonstrate the  
// crypto.webcrypto function
  
// Importing crypto module
const crypto = require('crypto')
  
// getting object of crypto 
// by using webcrypto function
const val = crypto.webcrypto
  
const buffer  = new ArrayBuffer(8)
  
//display the result
console.log(val.getRandomValues(Int16Array.of(buffer)))


Run the index.js file using the following command.

node index.js

Output:

Int16Array(1) [ 31796 ]

Example 2:

index.js




// Node.js program to demonstrate the  
// crypto.webcrypto function
  
//display the result
console.log((require('crypto').webcrypto)
.getRandomValues(Int16Array.of(new ArrayBuffer(8))))


Run the index.js file using the following command.

node index.js

Output:

Int16Array(1) [ -6968 ]

Reference: https://nodejs.org/dist/latest-v15.x/docs/api/crypto.html#crypto_crypto_webcrypto


Last Updated : 05 Apr, 2021
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads