Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Node.js crypto.webcrypto Property

  • Last Updated : 05 Apr, 2021

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

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!