Found 254 Articles for Node.js

crypto.getCiphers() Method in Node.js

Mayank Agarwal
Updated on 20-May-2021 12:31:42

190 Views

The crypto.getCiphers() method will return an array that contains names of all the supported cipher algorithms. The crypto package has a huge list of cipher algorithms we can use. But the most used cipher algorithm is 'AES – Advanced Encryption Standard'.Syntaxcrypto.getCiphers()ParametersSince it returns a list of all the cipher algorithms. It does not need to have any input.ExampleCreate a file with name – getCipher.js and copy the below code snippet. After creating file, use the following command to run this code as shown in the example below −node getCipher.jsgetCipher.js Live Demo// A node demo program for getting all cipher algorithms ... Read More

crypto.generateKeyPairSync() Method in Node.js

Mayank Agarwal
Updated on 20-May-2021 12:30:52

1K+ Views

The crypto.generateKeyPairSync() can be used to generate a new asymmetric key pair of the specified type in a sync flow. Supported types for generating key pair are: RSA, DSA, EC, Ed25519, Ed448, X25519, X448 and DH. The function behaves as if keyObject.export has been called on its result when a publicKeyEncoding or privateKeyEncoding is specified, else the respective part of keyObject is returned. The suggested type for public key is 'spki' and for private key it is 'pkcs8'.Syntaxcrypto.generateKeyPairSync(type, options)ParametersThe above parameters are described as below −type – It holds the string type for which keys needs to be generated. Supported types ... Read More

crypto.generateKeyPair() Method in Node.js

Mayank Agarwal
Updated on 20-May-2021 12:30:25

2K+ Views

The crypto.generateKeyPair() can be used to generate a new asymmetric key pair of the specified type. Supported types for generating key pair are: RSA, DSA, EC, Ed25519, Ed448, X25519, X448 and DH. The function behaves as if keyObject.export has been called on its result when a publicKeyEncoding or privateKeyEncoding is specified, else the respective part of keyObject is returned.Syntaxcrypto.generateKeyPair(type, options, callback)ParametersThe above parameters are described as below −type – It holds the string type for which keys needs to be generated. Supported types are - RSA, DSA, EC, Ed25519, Ed448, X25519, X448 and DH.options – It can hold the following Parameters −modulusLength – ... Read More

crypto.createVerify() Method in Node.js

Mayank Agarwal
Updated on 20-May-2021 12:26:22

426 Views

The crypto.createVerify() will create and return a verify object that uses the passed algorithm in the parameter. One can use, crypto.getHashes() to get the names of all the available signing algorithms. You can create a Verify instance by using the name of the signature algorithms such as 'RHA-SHA256' only in some of the cases, instead of a digest algorithm.Syntaxcrypto.createVerify(algorithm, [options])ParametersThe above parameters are described as below −algorithm – It takes the input for the algorithm name to be used while creating the verify object/instance.options – This is an optional parameter that can be used for controlling the stream behaviour.ExampleCreate a file with ... Read More

crypto.createSign() Method in Node.js

Mayank Agarwal
Updated on 20-May-2021 12:23:51

230 Views

The crypto.createSign() will create and return a sign object tha uses the passed algorithm in the parameter. One can use, crypto.getHashes() to get the names of all the available digest algorithms. You can create a Sign instance by using the name of the signature algorithms such as 'RHA-SHA256' only in some of the cases, instead of a digest algorithm.Syntaxcrypto.createSign(algorithm, [options])ParametersThe above parameters are described as below −algorithm – It takes the input for the algorithm name to be used while creating the sign object/instance.options – This is an optional parameter that can be used for controlling the stream behaviour.ExampleCreate a file ... Read More

crypto.createECDH() Method in Node.js

Mayank Agarwal
Updated on 20-May-2021 12:20:47

303 Views

The crypto.createECDH() is used to create an elliptic curve also known as Elliptic Curve Diffie-Hellman i.e ECDH that uses a curve predefined by the input parameter curveName. You can use crypto.getCurves to get the list of all the available curve names. This method is part of the 'crypto' module.Syntaxcrypto.createECDH(curveName)ParametersThe above parameters are described as belowcurveName – It takes the input for the curve name. This curveName will deined the predefined curve for creating ECDH.ExampleCreate a file with name – createECDH.js and copy the below code snippet. After creating file, use the following command to run this code as shown in the ... Read More

crypto.createDiffieHellmanGroup() Method in Node.js

Mayank Agarwal
Updated on 20-May-2021 12:20:24

79 Views

The crypto.createDiffieHellmanGroup() is used for creating the DiffieHellmanGroup. This method can also be referred as an alias for crypto.getDiffieHellman.Syntaxcrypto.createDiffieHelmmanGroup(name)ParametersThe above parameters are described as below −name – It takes the input for the group name. The input is of type 'string'.ExampleCreate a file with name – diffieHellmanGroup.js and copy the below code snippet. After creating file, use the following command to run this code as shown in the example below −node diffieHellmanGroup.jsdiffieHellmanGroup.js Live Demo// crypto.createDiffieHellmanGroup Demo Example // Importing the crypto module const crypto = require('crypto'); // Defining the group name const name = 'modp1'; // Creating DiffieHellman group ... Read More

crypto.createDecipheriv() Method in Node.js

Mayank Agarwal
Updated on 20-May-2021 12:20:01

2K+ Views

The crypto.createCipheriv() is a programming interface from the 'crypto' module. It will create and return the Decipher object as per the given algorithm, key, iv and options passed in the function.Syntaxcrypto.createDecipheriv(algorithm, key, iv, [options])ParametersThe above parameters are described as below −algorithm – It takes the input for the algorithm that would be used to create the cipher. Some possible values are: aes192, aes256, etc.key – It takes input for the raw key that is used by the algorithm and iv. Possible values can be of type: string, buffer, TypedArray or DataView. It can optionally be a type object of secret type.iv – ... Read More

crypto.createCipheriv() Method in Node.js

Mayank Agarwal
Updated on 20-May-2021 12:19:36

4K+ Views

The crypto.createCipheriv() method will first create and then return the cipher object as per the algorithm passed for the given key and authorization factor (iv).Syntaxcrypto.createCipheriv(algorithm, key, iv, options)ParametersThe above parameters are described as below −algorithm – It takes the input for the algorithm that would be used to create the cipher. Some possible values are: aes192, aes256, etc.key – It takes input for the raw key that is used by the algorithm and iv. Possible values can be of type: string, buffer, TypedArray or DataView. It can optionally be a type object of secret type.iv – Also known as the initialization vector. This ... Read More

cipher.update() Method in Node.js

Mayank Agarwal
Updated on 20-May-2021 12:09:13

486 Views

The cipher.update() is used to update the cipher with the receivd data according to the given encoding format. It is one of the inbuilt method that is provided by the class Cipher within the crypto module. If an input encoding is specified, the data argument is a string, else the data argument is a bufferSyntaxcipher.update(data, [inputEncoding], [outputEncoding])ParametersThe above parameters are described as below −data – It takes the data as an input that is passed to update the cipher content.inputEncoding – It takes the input encoding as a parameter. Possible input values are hex, base64, etc.outputEncoding – It takes the output encoding as ... Read More

Advertisements