VOOZH about

URL: https://www.geeksforgeeks.org/node-js/node-js-crypto-createdecipheriv-method/

⇱ Node.js crypto.createDecipheriv() Method - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Node.js crypto.createDecipheriv() Method

Last Updated : 28 Apr, 2025

The crypto.createDecipheriv() method is an inbuilt application programming interface of crypto module which is used to create a Decipher object, with the stated algorithm, key and initialization vector i.e, (iv). 

Syntax:

crypto.createDecipheriv( algorithm, key, iv, options )

Parameters: This method accept four parameters as mentioned above and described below:

  • algorithm: It is a string type value that dependent on OpenSSL. The examples are aes192, aes256, etc.
  • key: It is the raw key which is used by the algorithm and iv. It holds the string, Buffer, TypedArray or DataView. The key can be a KeyObject optionally of type secret.
  • iv: It is an initialization vector that must be uncertain and very unique. However, an ideal iv will be cryptographically random. It don't need to be secret. It can holds string, Buffer, TypedArray, or DataView type data. If cipher doesn't requires iv then it can be null.
  • options: It is an optional parameter that is used to control stream behavior. It is optional except when a cipher is used in CCM or OCB mode(e.g. 'aes-128-ccm'). In that case, the authTagLength option is required which defines the length(bytes) of the authentication tag whereas, in GCM mode, the authTagLength option is not needed but it can be used to set the length of the authentication tag that will be returned by the getAuthTag() method and the default value is 16 bytes.

Return Value: It returns Decipher object. 

Below examples illustrate the use of crypto.createDecipheriv() method in Node.js: 

Example 1: 

Output:

done
CS-Portal

Example 2: 

Output:

{ iv: '6bbc47a2756d6d6bf315cfd3cc0b711a', encryptedData: 'fae9a6fb31c0b0668da8c3be1b1da81a' }
GeeksforGeeks

Reference: https://nodejs.org/api/crypto.html#crypto_crypto_createdecipheriv_algorithm_key_iv_options

Comment

Explore