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
3
votes
1 answer

node crypto.publicEncrypt returns different value each time it is used

I'm trying to implement basic asymmetric encryption; one service has a public key and encrypts a value with that public key and then another service receives the encrypted message, decodes it using the private key, and does something with the…
sauntimo
  • 1,531
  • 1
  • 17
  • 28
3
votes
0 answers

How to decrypt Swift CryptoKit chacha20-poly1305 cipher in JavaScript?

I encrypted a string in swift using CryptoKit's ChaChaPoly: // Swift let txt: Data? = "secret message".data(using: .utf8) let key = SymmetricKey(data: SHA256.hash(data: "password".data(using: .utf8)!)) let sealedBoxData = try!…
user2779114
  • 51
  • 1
  • 6
3
votes
2 answers

How to generate persist and load keys using NodeJS?

I've been learning NodeJS and the crypto library. Specifically, I'd like to generate a signature and then verify it. I have working code for this below. The NodeJS Crypto library docs were adequate to figure this much out. I can also export those…
Brian
  • 395
  • 1
  • 3
  • 14
3
votes
1 answer

How does an IV work and what would be the best way to store it?

I want to encrypt and decrypt strings. I'm using Nodejs crypto for this. I've read that when encrypting and decrypting it's highly recommended to use an IV. I want to store the encrypted data inside a MySQL database and decrypt it later when needed.…
user12367845
3
votes
1 answer

What is hmac.new equivalent in node.js?

I want to HMAC SHA256 hash the normalized request using the client secret and base64 encode the result. I am getting different result in python and typeScript. My goal is to achieve python result in typeScript. How to do that? I was able to convert…
GThree
  • 2,708
  • 7
  • 34
  • 67
3
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
  • 2,538
  • 3
  • 27
  • 56
3
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,834
  • 6
  • 27
  • 41
3
votes
1 answer

Create a PGP Compatible Signature in NodeJS using the Crypto Library

In looking at the Crypto Library I see it has the capability to sign data. Does anyone know if a PGP compatible signature is as simple as ASCII armoring the output of the Crypto Library's sign command? I have an application that needs to sign and…
Doug
  • 6,446
  • 9
  • 74
  • 107
3
votes
1 answer

Encoding/Encrypting the Azure Log Analytics Authorization Header in node.js

I've been trying to get the Log Collector API working in a node.js Azure Function but am stuck on the 403/Forbidden error which indicates I'm not forming the authorization header correctly. The complete code is in a github repository…
Graham
  • 7,431
  • 18
  • 59
  • 84
3
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
  • 2,739
  • 1
  • 25
  • 39
3
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
  • 38,105
  • 35
  • 175
  • 251
3
votes
2 answers

Compatibility between node crypto and crypto-js encryption and decryption

How do I properly encrypt/decrypt data between node.js with the crypto module (server side) and crypto-js (client side, react-native)? NOTE: I'm using cryptojs in a react-native project, thus I can't use crypto on client. replacing crypto server…
3
votes
1 answer

Not a string or buffer. Module Crypto

I created on the module util.js a function myHash() for reuse in different parts of my code but not working. Error message: this._binding.update(data, encoding); Not a string or buffer. app.js ... GLOBAL.util = require('./util'); GLOBAL.dateFormat…
alditis
  • 4,633
  • 3
  • 49
  • 76
2
votes
1 answer

How to convert ECDH keys to PEM format with NodeJS crypto module

I want to have only one pair of keys that I can use for ECDH functions and for other function in node:crypto module. I know there are two ways how to generate keys with node:crypto module. One way is to use crypto.generateKeyPairSync. This generates…
David Novák
  • 1,455
  • 2
  • 18
  • 30
2
votes
1 answer

NodeJS Crypto equivalent in PHP?

I'm looking for a way to decrypt a file since a few weeks. But it's impossible to recover the file intact in PHP, only with node. But I would like to do it without node. If someone can tell me where I could be wrong... ? I tried with…
1 2
3
14 15