Found 6683 Articles for Javascript

crypto.privateDecrypt() Method in Node.js

Mayank Agarwal
Updated on 20-May-2021 13:36:53

1K+ Views

The crypto.privateDecrypt() is used for decrypting the given data content by using a private key passed in the parameter that was previously encrypted using the corresponding public key with crypto.publicEncrypt() method.Syntaxcrypto.privateDecrypt(privateKey, buffer)ParametersThe above parameters are described as below −key – It can contain the below 5 types of data of the following type – Object, String, Buffer or KeyObject.oaepHash – This field contains the hash function to be used for OAEP padding and MGF1. Default value is: 'sha1'.oaepLabel – This field contains the value for OAEP padding. No lable is used if not specified.padding – This is an optional value defined in crypto.constants.buffer – This ... Read More

crypto.getHashes() Method in Node.js

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

136 Views

The crypto.getHashes() method will return an array that contains names of all the supported hash algorithms. The crypto package has a huge list of hash algorithms we can use. But the most used cipher algorithm is 'MD5 – Message-Digest Algorithm5 '.Syntaxcrypto.getHashes()ParametersSince it returns a list of all the hash algorithms. It does not need to have any input.ExampleCreate a file with name – getHashes.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 getHashes.jsgetHashes.js Live Demo// A node demo program for getting all hash algorithms ... Read More

crypto.getDiffieHellman() Method in Node.js

Mayank Agarwal
Updated on 20-May-2021 12:50:59

124 Views

The crypto.createDiffieHellmanGroup() is used for creating a pre-determined DiffieHellmanGroup key exchange object. Some of the supported DiffieHellmanGroups are: modp1, modp2, modp5, modp 14, modp16, modp17 etc. The benefit of using this method is that the parties don't need to generate or exchange a group modulus thus saving processing time.Syntaxcrypto.getDiffieHelmmanGroup(groupName)ParametersThe above parameters are described as below −groupName – It takes the input for the group name. The input is of type 'string'.ExampleCreate a file with name – getdiffieHellman.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 ... Read More

crypto.getCurves() Method in Node.js

Mayank Agarwal
Updated on 20-May-2021 12:32:35

225 Views

The crypto.getCurves() method will return an array that contains names of all the supported elliptic curves. The crypto package has a huge list of elliptic curves that can be used for creating Elliptic Curve Diffie-Hellman (ECDH) key exchange objectSyntaxcrypto.getCurves()ParametersSince it returns a list of all the elliptic curves. It does not need any arguments.ExampleCreate a file with name – curves.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 curves.jscurves.js Live Demo// A node demo program for getting all elliptic curves // Importing the crypto ... Read More

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

427 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

231 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

308 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

Advertisements