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

160 questions
2
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 =…
2
votes
1 answer

[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
  • 561
  • 4
  • 14
2
votes
1 answer

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
  • 763
  • 2
  • 13
  • 30
2
votes
2 answers

C# Rfc2898DeriveBytes to node

I'm rewriting an encryption algorithm (implemented in C#) using Node. The encryption uses a 32-byte key and a 16-byte IV and it uses Rfc2898DeriveBytes to generate the key and IV. I have used crypto.pbkdf2Sync to generate a key of 48 bytes instead…
Nagendra Varma
  • 1,846
  • 3
  • 15
  • 24
2
votes
1 answer

How to store iv used to create cipher in nodejs's createcipheriv, for future decryption?

I'm new to cryptography and I'm using nodejs to serve an app. My app uses config files that I want to encrypt them before production, and when nodejs server needs these files (in production) it will decrypt them. I'm using…
2
votes
1 answer

Speeding up AES decryption in Node js

I wanted to create web page on which would be displayed data, previously decrypted on server. On server in app.js all of data from one folder is read and then decrypted. var http = require('http'); var path = require('path'); var express =…
Stageflix
  • 21
  • 3
2
votes
1 answer

Migrating from 'crypto' to crypto-js library: Binary encoding

I'm trying to generate SHA256 and HmacSHA512 hashes on a device which unfortunately has no support for the standard Node crypto library. So I am adjusting the code to use CryptoJS instead. However, CryptoJS cannot encode the Hash as in binary (only…
bluppfisk
  • 1,860
  • 2
  • 21
  • 39
2
votes
2 answers

Getting error(Error: Unsupported state or unable to authenticate data) in nodejs decryption

I have encrypted a message using AES/GCM/NoPadding algorithm(AES-256) in java & trying to decrypt it in NodeJs. Getting exception "Error: Unsupported state or unable to authenticate data" while decryption. Below is the complete code of java and…
Paddy02
  • 71
  • 11
2
votes
1 answer

Encrypt a string in nodejs and decrypt in java

I am encrypting a text in NODEJS and trying decrypt in Java but getting error. my nodejs code: var crypto = require('crypto') , key = 'mykey@91' , plaintext = 'SS18617710213463' , cipher = crypto.createCipher('aes-128-ecb', key) , decipher =…
2
votes
1 answer

AES/CBC/PKCS5PADDING IV - Decryption from Java to NodeJs

I am trying to decrypt in NodeJs. It is working in Java. But I am not able to achieve same in Node. I am using node-version: 8.4 Please find my NodeJs code: var crypto = require('crypto'); function decryption (message, key) { var messageArray =…
Chaitanya Joshi
  • 284
  • 1
  • 4
  • 21
2
votes
2 answers

cipher.js TypeError: IV must be a buffer

var path = require('path'); var fs = require('fs'); var crypto = require('crypto'); var algorithm = 'aes-256-ctr'; var password = 'xxxxx'; var dir = '/Users/antkong/some/path'; var file = 'somefile.json'; var clearTextPath = path.join(dir,…
Anthony Kong
  • 29,857
  • 33
  • 139
  • 244
2
votes
0 answers

Validate file signature in Node.js

I have a pdf file signed in Adobe Reader with some Key Algorithm, say 1024-bit RSA. How can I validate the signature in Node.js having both signed file and Public Key? I know there is a native module crypto. But I cannot understand how to use it,…
alex.mironov
  • 2,554
  • 3
  • 25
  • 33
2
votes
2 answers

Mongoose getters and setters not functioning properly

I'm trying to encrypt and decrypt values before and after inserting to MongoDB. I'm using mongoose schema and calling the get and set methods for encryption and decryption. The data is getting encrypted by calling set method, but while retrieving…
NagaRajendra
  • 151
  • 3
  • 15
2
votes
0 answers

Node.js support of X25519 curve

I don't see node crypto having any implementations of X25519 curve. I've checked through crypto.getCurves() Am I looking at something wrong or is Node not supporting this curve yet. If so, are there any other alternatives to use this curve in node's…
manikawnth
  • 1,819
  • 14
  • 30
2
votes
1 answer

Converting Java crypto code to NodeJS

I am working on implementing the Walmart API in NodeJS. Walmart only provides JAVA examples. I am having issues getting it right. My signature is a bit longer and not accepted when compared to using the Java executable they provide. I'd appreciate…
cyberwombat
  • 31,246
  • 30
  • 143
  • 210
1 2
3
10 11