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
213
votes
3 answers

How do I use Node.js Crypto to create a HMAC-SHA1 hash?

I want to create a hash of I love cupcakes (signed with the key abcdeg) How can I create that hash, using Node.js Crypto?
user847495
  • 8,403
  • 15
  • 42
  • 47
72
votes
6 answers

How to encrypt data that needs to be decrypted in node.js?

We are using bcrypt for hashing passwords and data that never needs to be decrypted. What should we do to protect other user information that does need to be decrypted? For example, let's say that we didn't want a user's real name to be in plain…
fancy
  • 41,315
  • 56
  • 147
  • 225
65
votes
3 answers

Using SHA-256 with NodeJS Crypto

I'm trying to hash a variable in NodeJS like so: var crypto = require('crypto'); var hash = crypto.createHash('sha256'); var code = 'bacon'; code = hash.update(code); code = hash.digest(code); console.log(code); But looks like I have…
Cameron
  • 24,868
  • 91
  • 263
  • 449
61
votes
9 answers

How to create a pair private/public keys using Node.js crypto?

I have to generate two keys (private and public) to encrypt a text with the public and let the user with the private key decrypt the text. Is it possible with the module Crypto?
Dail
  • 4,058
  • 14
  • 68
  • 100
42
votes
7 answers

SALT and HASH password in nodejs w/ crypto

I am trying to figure out how to salt and hash a password in nodejs using the crypto module. I am able to create the hashed password doing this: UserSchema.pre('save', function(next) { var user = this; var salt =…
lostintranslation
  • 20,811
  • 42
  • 129
  • 220
16
votes
1 answer

Do i need to install crypto module from npm?

I am making use of crypto module in my app. It seems like there is crypto module distributed in nodejs http://nodejs.org/api/crypto.html so do i need to do npm install crypto? what is the difference from https://npmjs.org/package/crypto and nodejs…
Yalamber
  • 6,783
  • 13
  • 57
  • 80
14
votes
1 answer

How to create random-salt-hash with crypto

I want to create a salt-hash using node.js crypto lib without having to parse any hardcoded data. What do I mean with hardcoded? var salt, hardcodedString = "8397dhdjhjh"; crypto.createHmac('sha512',…
dev.pus
  • 7,047
  • 12
  • 34
  • 49
13
votes
2 answers

Why crypto.createHash returns different output in new version?

Problem I have node.js module that is using crypto.createHash to generate md5 hash. Recently I noticed that hash generated by crypto module is different in new versions: Code require('crypto').createHash('md5').update('¥').digest('hex') Node.js…
gevorg
  • 4,273
  • 4
  • 32
  • 49
12
votes
1 answer

Using public key to verify signature in Node.JS crypto

Is there a good way to validate signatures in Node.JS (v0.4+) with public keys? Current crypto module allows this with certificates but not with public keys. For example: var crypto = require("crypto"); verifier =…
Andris
  • 26,410
  • 2
  • 31
  • 36
12
votes
1 answer

Node JS crypto, cannot create hmac on chars with accents

I am having an issue generating the correct signature in NodeJS (using crypto.js) when the text I am trying to encrypt has accented characters (such as ä,ï,ë) generateSignature = function (str, secKey) { var hmac = crypto.createHmac('sha1',…
Tommy
  • 178
  • 1
  • 2
  • 16
10
votes
3 answers

Node.js and crypto library

I'm having weird issues with Node's crypto library. I wrote this simple AES testing script: var cipher = crypto.createCipher('aes-256-cbc','InmbuvP6Z8') var text = "123|123123123123123"; cipher.update(text,'utf8','hex') var crypted =…
Mike
  • 113
  • 1
  • 2
  • 6
10
votes
2 answers

EVP_DecryptFinal_ex:bad decrypt when using Node.js

Using the following node js: var crypto = require('crypto'); var encrypt = function (input, password, callback) { var m = crypto.createHash('md5'); m.update(password); var key = m.digest('hex'); m = crypto.createHash('md5'); …
Sonu Kapoor
  • 1,357
  • 2
  • 15
  • 32
10
votes
1 answer

Error handling in using Crypto in Node.js

I am using Crypto library of Node.js for encryption/decryption as follows : encrypt = function(text, passPhrase){ var cipher = crypto.createCipher('AES-128-CBC-HMAC-SHA1', passPhrase); var crypted =…
Danial
  • 663
  • 1
  • 11
  • 26
8
votes
1 answer

Node.js - Set padding in crypto module

I've been looking over the docs for the crypto module in Node, and I'm trying to figure out how to set the padding when doing symmetric encryption. I'm trying to use AES-128-ECB, with PKCS5 padding. I can't see anywhere that it allows you to specify…
dsw88
  • 4,102
  • 7
  • 35
  • 47
7
votes
4 answers

nodejs crypto module vs crypto-js

I'm quite new to NodeJs and trying to figure out how to use the "crypto" module. While playing around with it I notice the difference between the "crypto" module in NodeJs and crypto-js: With crypto-js, I have: function SHA256Hash(password, salt,…
Mono
  • 71
  • 1
  • 1
  • 4
1
2 3
10 11