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

Encrypting and decryping the data using public and private key in node.js?

I have a private key as well as an ethereum public address. I want to encrypt a payload using a user public ethereum address and then give it to that user and then he can decrypt it using his private key. Or i can encrypt it using user public key…
Hsn
  • 1,168
  • 2
  • 16
  • 39
1
vote
1 answer

PHP AES Encryption into NodeJS using crypto module

My task is to follow the given and working PHP encryption into node.js. using any node module packages. I dont need to do the decryption because its already existing in their API and i just need to pass the encypted value to their API for decryption…
Makopa
  • 91
  • 9
1
vote
1 answer

Node crypto.randomBytes return token from function

Summary I have a function where I use crypto.randomBytes to generate a token and I'm having trouble returning the token from the function. I want to return token from createResetToken. My function is below and I've tried many different things but…
bzlight
  • 1,066
  • 4
  • 17
  • 43
1
vote
1 answer

How to verify file using rsa public key

I base my work on this answer I'm trying to verify a file using a public key. Here is my code: var hash = crypto.createHash("sha256"); hash.setEncoding("hex"); var fd = fs.createReadStream("path/to/my/file"); fd.on("end", function() { …
iAmoric
  • 1,787
  • 3
  • 31
  • 64
1
vote
0 answers

RSAES-PKCS1- V1_5 Public encryption using NodeJs crypto

I am facing up a bit of a wall trying to send encrypted data over to a remote server using the NodeJs crypto module. According to the API docs, the payload needs to be encrypted using the AES-256 algorithm with randomly generated KEY and IV. The…
bentesha
  • 898
  • 9
  • 14
1
vote
1 answer

Encrypt in Nodejs and Decrypt in PHP

I'm trying to decrypt a string in PHP which was originally encrypted in NodeJS. PHP: openssl_decrypt($raw_id, "aes-128-cbc", "s7UbmJpfm56r6CAC6mz7KVZdRc3Fxc4m", 0, null) This seems to always returnfalse. Encryption in Nodejs: function encrypt(text)…
Appel Flap
  • 261
  • 3
  • 23
1
vote
1 answer

Encrypt in CryptoJS and decrypt in NodeJS Crypto module

I have searched here and googled, but couldn't really find what I am looking for. Looks like this should be pretty easy but few similar threads went unanswered as SO. I am hoping if I get the answer. So I have this fiddle JS Fiddle which encrypts…
Oo-_-oO
  • 417
  • 7
  • 24
1
vote
2 answers

Is it possible to decipher at random position with nodejs crypto?

My understanding is that an AES block cipher in CTR mode allows, in theory, to decipher any location of a large file, without needing to read the whole file. However, I don't see how to do this with nodejs crypto module. I could feed the…
youen
  • 1,952
  • 1
  • 23
  • 32
1
vote
2 answers

Node - require('crypto') resolves to { }

I'm using NPM for dependency management and Angular5 with TypeScript. EDIT I haven't installed the crypto package from npm, I am referencing the node inbuilt package. No matter what I do, the "crypto" package resolves as an empty object. I have…
Eric
  • 433
  • 5
  • 12
1
vote
1 answer

Node decrypt content with private key and padding

So, I have a content which needs to be decrypted with private key and padding AES/ECB/PKCS5Padding. I tried many libraries, and many examples, but none of them works. Now, this is the one where I managed to finish to the last steps, but im not sure…
Miljan Vulovic
  • 1,586
  • 3
  • 20
  • 48
1
vote
0 answers

Port Node js Crypto.publicEncrypt to Java

I have a the following code in Node.js let publicKeyString = '-----BEGIN PUBLIC KEY-----RANDOMPUBLICKEYOMITTED-----END PUBLIC KEY-----\n'; let publicKey = { key: publicKeyString, padding: 1 } function _encrypt(input,…
swilliz
  • 13
  • 4
1
vote
1 answer

Encryption (aes-128-cbc) not matching between python(pycrypto) and nodejs(crypto)

I have got this piece of python code which I need to translate into nodejs. The python code uses pycrypto from encryption. On the nodejs side, I am using the native crypto module. There seems to be a mismatch between the encrypted strings. from…
1
vote
1 answer

Node JS crypto "Bad input string"

Want to decrypt a string from file. But when i use nodejs decipher on the string from fs, it gives the error "Bad input string" var fs = require('fs'); var crypto = require('crypto'); function decrypt(text){ var decipher =…
Stweet
  • 683
  • 3
  • 11
  • 26
1
vote
1 answer

PHP mcrypt_decrypt in NodeJS

I've been hunting the internet for the last 3 hours and I've finally decided to ask the question. Is is possible to decrypt a base64 text string in NodeJS that was encrypted through PHP. I've tried many steps to break it down but nothing I do seems…
Matthew Auld
  • 388
  • 1
  • 3
  • 18
1
vote
1 answer

node crypto key derivation from a password produces different results with browserify

I'm trying to re-create Symfony's MessageDigestPasswordEncoder in the browser. I have some issue with browserify and crypto module. I try to generate hash with JavaScript but without Node. Here is my code with node: var crypto =…
Dcp
  • 66
  • 7