Questions tagged [node-crypto]

Node.js crypto module provides cryptographic functionality that includes a set of wrappers for OpenSSL's hash, HMAC, cipher, decipher, sign and verify functions. Use this tag for questions related to Node.js applications/scripts that use crypto module - require('crypto').

should be used on questions related to cryptography api of

The crypto module provides cryptographic functionality that includes a set of wrappers for OpenSSL's hash, HMAC, cipher, decipher, sign and verify functions.

Sample

// Import module.
const crypto = require('crypto');

// Prepare secret.
const secret = 'very secret';

// Create hash.
const hash = crypto.createHmac('sha256', secret)
                   .update('sample information')
                   .digest('hex');

// Print it.
console.log(hash);
// => 5087be71f85fd1ea755742b0fe4eaf5a7c4c25bee5db58f4f7edd1558ed792d0

References

220 questions
7
votes
4 answers

Node.js crypto.randomBytes() is not a function

For some reason a function I am trying to use is, apparently, not a function. Welcome to Node.js v14.15.1. Type ".help" for more information. > const crypto = require("crypto"); undefined > x = crypto.randomBytes(32).toString("hex") Uncaught…
Jake Jackson
  • 1,055
  • 1
  • 12
  • 34
7
votes
0 answers

Node.js crypto module - ECDH

I'm trying to accomplish a key exchange between Node.js using the crypto module and a web client using the Web Cryptography API. So far I managed to process the key exchange to the point where I derive the shared secret on the server and the client…
5
votes
3 answers

Node JS decipher.final() throws "wrong final block length" error

I am trying to encrypt/decrypt. Encryption works fine and it writes encrypted data to file. While decrypting I am getting an error of length issue. I have used "utf-8" format but error continues. / A decrypt function function decrypt(file) { let…
Chandu
  • 962
  • 2
  • 16
  • 33
5
votes
0 answers

Node Crypto diffieHellman.setPrivateKey()

I have been using the Crypto lib in Node for doing Pub Key exchange. So far I have just been using .getDiffieHellman('modp5') generate a new public / private key for each new connection. This methodology works great for computing a secret for use…
5
votes
1 answer

NodeJS Crypto with RC4 yields blank

I have a php function that generates an RC4 encrypted string. I would like to decode that string using Node - ideally using the built in Crypto module. But I am unable to do so - I just get a blank string. The PHP code is here…
cyberwombat
  • 38,105
  • 35
  • 175
  • 251
4
votes
1 answer

Convert Node crypto aes-256-cbc to CryptoJS

How to convert the following Node's built-in crypto module encryption to CryptoJS? const crypto = require('crypto'); const pass = 'some,password:)with>spec(chars*' const cipher1 = crypto.createCipher('aes-256-cbc', pass) const c1 =…
vahdet
  • 6,357
  • 9
  • 51
  • 106
4
votes
1 answer

How to create openssl encryption and decryption equivalent of php code in nodejs application

I have an application running on php which have some values encrypted using openssl encrption by using the code below
Ajith
  • 2,476
  • 2
  • 17
  • 38
4
votes
1 answer

Node JS crypto.createCipheriv Error: Invalid key length

I am trying to encrypt text in using node.js crypto module. Here is code: const crypto = require('crypto'); const password = 'password'; const key = crypto.scryptSync(password, 'salt', 24); const iv = crypto.randomBytes(16); const cipher =…
4
votes
2 answers

[Nodejs - Crypto][JSencrypt] rsa routines:RSA_padding_check_PKCS1_OAEP_mgf1:oaep decoding error

I'm using NodeJS Crypto module for encrypting and decrypting with RSA in backend and JSencrypt for frontend RSA But issue is my backend throws this error whenever I encrypt in frontend using publickey (PS: I'm using this in NuxtJS so using import…
Swapnil Soni
  • 965
  • 1
  • 10
  • 26
4
votes
1 answer

NodeJS Crypto randomBytes to string hex doubling size

I'm experiencing an odd issue using NodeJS crypto and the crypto.randomBtyes function. I've detected strange behaviorthat seems to have only recently appeared in my NodeJS / Typescript 3.2 application. The error makes sense in its own right:…
Chason Arthur
  • 519
  • 1
  • 11
  • 22
4
votes
3 answers

How to encrypt and decrypt string/object in nodejs

I would like to encrypt an object then decrypt it. The encryption works very well but the decryption fails. Below my code : crypto_ext.js const crypto = require("crypto") const password = "shared_key" const algorithm = "aes256" export const encrypt…
Maria Minh
  • 1,219
  • 4
  • 15
  • 27
4
votes
1 answer

crypto createHMAC output differs according to nodejs version

I have issues with crypto module while upgrading my node version. The created HMAC depends on the version of node. You'll find below the piece of code that reproduces the problem. If I encode my key as BASE64 (or any) the HMAC does not depends on…
dao hodac
  • 361
  • 2
  • 5
  • 14
4
votes
1 answer

Nodejs crypto vs python hashlib

I'm trying to make a python function and a nodejs function compute the same hash. However, it seems like the binary that is outputted is different between nodejs crypto and python hashlib. The python I'm using is: hash =…
Jon Chu
  • 1,877
  • 2
  • 20
  • 19
4
votes
1 answer

Node.js Crypto input/output types

I am trying to figure out the Node.js Crypto library and how to use it properly for my situation. My Goal is: key in hex string 3132333435363738313233343536373831323334353637383132333435363738 text in hex string…
Adam Magaluk
  • 1,716
  • 20
  • 29
3
votes
1 answer

'ERR_OSSL_EVP_WRONG_FINAL_BLOCK_LENGTH' while decryption in node js

I have used AES encryption in java as below and trying to decrypt in javascript JAVA : byte[] input = "data".getBytes(); MessageDigest md = MessageDigest.getInstance("SHA-256"); byte[] thedigest =…
Shik
  • 31
  • 1
1
2
3
14 15