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
2 answers

Crypto in NodeJS fails when unicode characters

I'm trying to validate data integrity using NodeJS Crypto library. It requires calculating the Hmac of a JSON string. After some test, I've been able to locate the issue: it happens whenever it contains a unicode character. For instance: var hasher…
Michael Gallego
  • 1,746
  • 1
  • 20
  • 29
1
vote
1 answer

Problems with node.js crypto module

I am trying to create an HMAC for use in authentication with an API. However, I'm running into some issues with the standard node crypto. Looking at this example under the Authentication section: HMAC_SHA256 ( 13916834993JJHlXeDcFM ,…
Anthony
  • 13,434
  • 14
  • 60
  • 80
1
vote
1 answer

node.js crypto module cannot encrypt 16+ characters

I am still rather new to all the terminology around cryptology, so please excuse my ignorance on the subject. I am having something strange happening when using node.js' crypto module. It will encrypt exactly 16 characters only. Any more and it…
tutiplain
  • 1,427
  • 4
  • 19
  • 37
1
vote
1 answer

Crypto error on decipher.update

I'm writing a javascript module for a Node project. I get a very ambiguous error protocol\Parser.js:82 throw err; TypeError: error:0000000:lib(0):func(0):reason(0) at Decipher.Cipher.update (crypto.js:279:27) Below is my javalogin.js…
MaylorTaylor
  • 4,671
  • 16
  • 47
  • 76
1
vote
1 answer

PKCS5 Padding with node.js crypto

The docs for node.js crypto indicate that padding is inserted automatically into the input stream. I have a simple test program that needs to compute the SHA1 hash of a cleartext, then encrypt that 20-byte hash use AES-256/CBC with PKCS5 padding. …
Greg R
  • 133
  • 3
  • 8
1
vote
2 answers

Node js crypto sign returns empty string

I am wanting to sign a string with a private key using crypto. The sign method returns an empty string, I was hoping to get a signiture. var crypto = require('crypto'); var message = "This is a string I want to ensure is not tampered with."; var…
bluelightzero
  • 33
  • 1
  • 7
1
vote
0 answers

how to enable crypto in node js

I am including crypto module in node.js, but its methods are not accessible var crypto = require("crypto"); exports.testSHA = function(req,res) { var shasum = crypto.createHash('sha1'); } on createHash it says Unresolved function or method…
JN_newbie
  • 5,492
  • 14
  • 59
  • 97
1
vote
2 answers

Is there a way to add a custom crypto algorithm into nodejs crypto module? How?

I need to generate a hash on each uploaded file. The hash must be identical to hash git generated for a given file (which is, in a layman term, a variant of sha1). I looked into /nodejs-v0.10.22-src/core-modules-sources/lib/crypto.js. The library…
Thomas - BeeDesk
  • 1,008
  • 1
  • 11
  • 12
1
vote
0 answers

Node.js crypto module crash on Amazon AMI instance

I'm stuck on a issue with crypto module of node.js in my production instance of my app, When I use "pbkdf2Sync" function in an Amazon instance, it's works terrible and for the same sets of values returns different values. I make a little script to…
1
vote
1 answer

Node.js Builtin Crypto: RSA Decryption

I'm using node.js 0.10.12. I have generated 2048-bit RSA keypairs that I store as .pem files locally. Using the built-in 'crypto' library that comes with node, I am trying to decrypt a block of data encrypted with the public RSA key mentioned…
zra
  • 141
  • 1
  • 13
1
vote
1 answer

Error in crypto deciphering

Why does the following code throw up a DecipherFinal error in crypto - var crypto = require('crypto'); c=new Date; x= (c.getTime()+"."+c.getMilliseconds()).toString()+".uIn"; key = 'sevsolut' , plaintext = x , cipher =…
digster
  • 392
  • 5
  • 20
1
vote
1 answer

Node.js Crypto encrypt with -nosalt option

From this post: What's wrong with nodejs crypto decipher? I figured out that to make my code work I need to encrypt my data with the openSSL -nosalt option beacuase of the way the node.js crypto library works. Since I am using the Node.js crypto…
Ari Porad
  • 2,834
  • 3
  • 33
  • 51
0
votes
1 answer

`node:crypto` to generate a sha256 password hash?

I am trying to do the equivalent of openssl passwd -6 in nodejs using the crypto library. My attempt was to use this function: import * as crypto from "node:crypto"; import { promisify } from "node:util"; const pbkdf2 =…
d_inevitable
  • 4,381
  • 2
  • 29
  • 48
0
votes
1 answer

Reimplementing createCipher with crypto-js

I have these two code snippets. The first one uses createCipher from node:crypto and the second one is supposed to generate the same result using CryptoJS: const dataText = 'Hello'; const crypto = require('node:crypto'); const c =…
bjornd
  • 22,397
  • 4
  • 57
  • 73
0
votes
4 answers

Why won't vite server start?

I get an error when I start the dev server error when starting dev server: TypeError: Cannot redefine property: crypto at Function.defineProperty () at installPolyfills…
Player
  • 1
  • 2