Found 254 Articles for Node.js

crypto.scrypt() Method in Node.js

Mayank Agarwal
Updated on 20-May-2021 13:04:04

622 Views

The crypto.scrypt() method provides an asynchronous implementation for scrypt method. The scrypt can be defined as a password-based key derivation function that protects the system from the brute-force attacks and makes it unawarding. But the script function is expensive computationally as well as memory-wise.Syntaxcrypto.scrypt(password, salt, keylen, [options], [callback])ParametersThe above parameters are described as below −password – The password field for the scrypt required to decode entry. It can be a string, object, TypedArray, etc.salt – This value should be as unique as possible. This is mainly used for encrypting the data. The minimum suggested length of salt is 16 bytes.keylen – This parameter ... Read More

crypto.randomFillSync() Method in Node.js

Mayank Agarwal
Updated on 20-May-2021 13:03:17

314 Views

The crypto.randomFillSync() method takes a buffer argument and returns the buffer by filling it with its encrypted value. As the name suggests, this will be a sync process.Syntaxcrypto.randomFillSync(buffer, [offset], [size])ParametersThe above parameters are described as below −buffer – This field contains the data content. Possible buffer types are: string, TypedArray, Buffer, ArrayBuffer, DataView. The size of the buffer cannot be greater than 2**31-1.offset – The value of the offset from where randomFill will start. Default value is 0.size – The size of the buffer after the offset, i.e., (buffer.length-offset). This value cannot be greater than 2**31-1.ExampleCreate a file with name – randomFillSync.js and ... Read More

crypto.randomFill() Method in Node.js

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

170 Views

Both the crypto.randomFill() method and crypto.randomBytes() method are almost same. The only difference between the two is that – In randomFill() method the first argument is a buffer that will be filled. It also has a callback method that is called when an error is encountered only if the callback is configured.Syntaxcrypto.randomFill(buffer, [offset], [size], [callback])ParametersThe above parameters are described as below −buffer – This field contains the data content. Possible buffer types are: string, TypedArray, Buffer, ArrayBuffer, DataView. The size of the buffer cannot be greater than 2**31-1.offset – The value of the offset from where randomFill will start. Default value is ... Read More

crypto.publicEncrypt() Method in Node.js

Mayank Agarwal
Updated on 20-May-2021 12:54:03

1K+ Views

The crypto.publicEncrypt() is used for encrypting the given data in buffer parameter by using a public key passed in the parameter. The data returned can be decrypted using the corresponding private key.Syntaxcrypto.publicEncrypt(key, 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.key – This field contains the PEM encoded public or private key. It can be of type 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 ... Read More

crypto.publicDecrypt() Method in Node.js

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

523 Views

The crypto.publicDecrypt() is used for decrypting the given data in buffer with public key. This buffer was encrypted by using the corresponding private key i.e. crypto.privateEncrypt() method.Syntaxcrypto.publicDecrypt(key, 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.passphrase - This is an optional passphrase for the private key.padding – This is an optional value defined in crypto.constants.encoding – This is the type of encoding that needs to be used when buffer, key, oaepLabel or passphrase value are strings.buffer – This field contains the data content to be ... Read More

crypto.privateEncrypt() Method in Node.js

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

519 Views

The crypto.privateEncrypt() is used for encrypting the given data content by using the given private key parameter passed in the function.Syntaxcrypto.privateEncrypt(privateKey, buffer)ParametersThe above parameters are described as below −privateKey – It can contain following data types – Object, String, Buffer or KeyObject.key – This key is a 'PEM' encoded private key. The key can be of type string, buffer or KeyObject.passphrase – This is an optional passphrase value for the private key.padding – This is an optional value defined in crypto.constants.buffer – This field contains the data content to be decrypted. Possible buffer types are: string, TypedArray, Buffer, ArrayBuffer, DataView.ExampleCreate a file with name – ... Read More

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

123 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

Advertisements