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
1
vote
1 answer

NodeJS - HMAC-SHA512 Equivalent code in Node from C#

using System; using System.Text; using System.Globalization; using System.Security.Cryptography; public class Program { public static void Main() { var id = "integration"; var key = "SECRET_KEY";…
Shanon Jackson
  • 5,873
  • 1
  • 19
  • 39
1
vote
1 answer

Converting PHP AES-256-CBC encryption into node.js

I have little to no knowledge in encryption and I've been facing issues trying to figure out how to convert these PHP functions to work with node.js and the crypto module. function encryptAES($str,$key) { $iv = "PJKKIOKDOICIVSPC" $str =…
1
vote
1 answer

Is it safe to reuse the hash object created by the crypto module in NodeJS?

To hash a payload with nodejs, I can use the crypto module and do: const crypto = require('crypto'); const payload = "abc123"; const hashObj = crypto.createHash('sha256'); const res = hashObj.update(payload).digest('hex'); Now say I want to hash a…
user8352734
1
vote
1 answer

Subtle Crypto Importing PCKS RSA Key leads to ERR_OSSL_ASN1_WRONG_TAG

I'm trying out the subtle crypto methods in Node.js 18. I want to import a private RSA Key. I copied the example straight from the MDN docs (https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/importKey#pkcs_8_import) and rewrote it to be…
ffritz
  • 2,180
  • 1
  • 28
  • 64
1
vote
1 answer

Node.js: Wrong crypto output

Node.js strangely gives me wrong output when decrypting hex–encoded AES128 output. function decrypt_data( data, key, iv ) { var dc = crypto.createDecipheriv( 'aes-128-cbc', hex_to_str(key), hex_to_str(iv) ); var res = dc.update( data, 'hex',…
Aleksei Zabrodskii
  • 2,220
  • 3
  • 19
  • 41
1
vote
0 answers

How to encrypt large file in buffer with public key in nodejs

I would like to encrypt file saved in Buffer type and return its Base 64 format. This is my code: encrypt(fileInBuffer: Buffer, publicKey: string): string { const encrypted = publicEncrypt(publicKey, fileInBuffer) return…
Marcin Warzybok
  • 357
  • 4
  • 16
1
vote
0 answers

encrypt long string with node js module crypto

i am trying to encrypt long tokens but i get error Error: Trying to add data in unsupported state import * as crypto from 'crypto'; import { APP_CONFIG } from "@app-config"; const algorithm = 'aes-256-cbc'; const cipher =…
user8987378
  • 182
  • 1
  • 2
  • 17
1
vote
1 answer

AES GCM encryption decryption in nodejs & Java

So, we are using AES GCM encryption & decryption in nodejs as follows, We need to use this in Java. So one can encrypt in Java and decrypt in nodeJs and vice versa. here is encrypt decrypt function in node const encrypt = (text, masterkey) => { …
Uday Solanki
  • 39
  • 2
  • 7
1
vote
0 answers

Nodejs Crypto to Swift commonCrypto

Wanted to convert the following Node Crypto example to equivalent Swift commonCrypto: function encrypt(key, text){ let iv = crypto.randomBytes(IV_LENGTH); let cipher = crypto.createCipheriv('aes-256-cbc', Buffer.from(key), iv); let…
Nah
  • 1,690
  • 2
  • 26
  • 46
1
vote
1 answer

Is there a way to get same encrypted hash value with some secret key?

I want to encrypt sensitive data in an encrypted format and save it to db. But later I have to be able to decrypt with a secret key used to decrypt. Importantly, encryption must give always the same hash. const algorithm = 'aes256'; const iv =…
coolisuz
  • 33
  • 4
1
vote
0 answers

Decrypting selling partner api reports

I am trying to decrypt selling partner api reports but while decrypting I am getting this error near decipher.final() [Node] Error: error:0606506D:digital envelope routines:EVP_DecryptFinal_ex:wrong final block length. The api returns the key, iv…
1
vote
1 answer

Trouble reproducing SubtleCrypto in Crypto

I have some code utilizing SubtleCrypto that encrypts a key and stores it in a database. For another functionality i have to be able to encrypt it in Node 12. Without SubtleCrypto i have to recreate the functionality in Crypto. I get output of the…
1
vote
1 answer

decrypt file use aes-256-cbc node.js iv undefind

my key : crypto.createHash('sha256').update('mySup3rC00lP4ssWord').digest() my iv : crypto.randomBytes(16) I try methods in this page : https://medium.com/@brandonstilson/lets-encrypt-files-with-node-85037bea8c0e I use aes-256-cbc to decrypt a…
1
vote
1 answer

Decrypting ChaCha20-Poly1305 binary data in NodeJS that was encrypted in python application from a string

We have a Python application that stores strings as encrypted binary data in MongoDB, it uses from cryptography.hazmat.primitives.ciphers.aead import ChaCha20Poly1305 On the NodeJS side I've been having trouble figuring out how to decrypt the data,…
1
vote
1 answer

Cannot convert PHP OpenSSL IV to Node.JS

I'm trying to convert my symmetric AES-256-CBC encryption from PHP to NodeJS. But i think i'm not converting correctly the IV, and i tried different things, but not worked. My PHP Code:
João Pedro
  • 115
  • 1
  • 12