node-crypto

EVP_DecryptFinal_ex:bad decrypt when using Node.js

偶尔善良 提交于 2019-12-04 02:55:20
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'); m.update(password + key); var iv = m.digest('hex'); console.log(iv); var data = new Buffer(input, 'utf8').toString('binary'); var cipher = crypto.createCipheriv('aes-256-cbc', key, iv.slice(0,16)); var encrypted = cipher.update(data, 'binary') + cipher.final('binary'); var encoded = new Buffer(encrypted, 'binary').toString('base64'); callback(encoded); }; var decrypt =

Node JS crypto, cannot create hmac on chars with accents

北战南征 提交于 2019-11-30 17:51:04
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', secKey); var sig = hmac.update(str).digest('hex'); return sig; }; This function will return the correct HMAC signature if 'str' contains no accented characters (chars such as ä,ï,ë). If there are accented chars present in the text, it will not return the correct HMAC. The accented characters are valid in UTF8 encoding so I dont know why crypto has a problem

NodeJs Crypto error -Object has no method pbkdf2Sync

故事扮演 提交于 2019-11-29 18:09:21
I am using nodeJS Crypto Module to encrypt password. Sample code: crypto.pbkdf2Sync(password, salt, 200, 64).toString('base64'); But I am not sure, whenever I call this method, following error shown TypeError: Object # has no method 'pbkdf2Sync' Please let me know what is the issues Thanks all apsillers pbkdf2Sync was added to the Crypto module in version 0.9.3. You can either upgrade your installation of Node to 0.9.3 or higher, or you can use the asynchronous version of the function, crypto.pbkdf2 , which requires a callback. If your previous code looked like var result = crypto.pbkdf2Sync

Why crypto.createHash returns different output in new version?

回眸只為那壹抹淺笑 提交于 2019-11-29 02:02:06
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 v0.10.0 Outputs: ab3af8566ddd20d7efc9b314abe90755 Node.js v6.1.0 Outputs: 07625e142e4ac5961de57472657a88c1 Question I was wondering what causes that in new version and how can I solve this? Update Similar issues on GitHub: https://github.com/nodejs/node/issues/6813 https://github.com/node-xmpp/client/issues/206 robertklep Some inputs in Node v6+

Node.js and crypto library

一曲冷凌霜 提交于 2019-11-28 23:50:11
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 = cipher.final('hex') var decipher = crypto.createDecipher('aes-256-cbc','InmbuvP6Z8') decipher.update(crypted,'hex','utf8') var dec = decipher.final('utf8') When I do console.log(dec), it's null. For some reason if I set test to "123|123123", it works. So why does "123|123123" work but "123|123123123123123" doesn't? RandomEtc You need to store the return from

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

烈酒焚心 提交于 2019-11-28 17:24:48
问题 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? 回答1: nodejs v10.12 now supports this natively with crypto.generateKeyPair const { generateKeyPair } = require('crypto'); generateKeyPair('rsa', { modulusLength: 4096, publicKeyEncoding: { type: 'spki', format: 'pem' }, privateKeyEncoding: { type: 'pkcs8', format: 'pem', cipher: 'aes-256-cbc', passphrase: 'top secret'

SALT and HASH password in nodejs w/ crypto

南笙酒味 提交于 2019-11-28 17:03:26
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 = crypto.randomBytes(128).toString('base64'); crypto.pbkdf2(user.password, salt, 10000, 512, function(err, derivedKey) { user.password = derivedKey; next(); }); }); However I am confused about how to later validate the password. UserSchema.methods.validPassword = function(password) { // need to salt and hash this password I think to compare // how to I get the salt? } In whatever

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

无人久伴 提交于 2019-11-28 02:41:02
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? Documentation for crypto: http://nodejs.org/api/crypto.html var crypto = require('crypto') , text = 'I love cupcakes' , key = 'abcdeg' , hash hash = crypto.createHmac('sha1', key).update(text).digest('hex') A few years ago it was said that update() and digest() were legacy methods and the new streaming API approach was introduced. Now the docs say that either method can be used. For example: var crypto = require('crypto'); var text = 'I love cupcakes'; var secret = 'abcdeg

Why crypto.createHash returns different output in new version?

老子叫甜甜 提交于 2019-11-27 16:21:16
问题 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 v0.10.0 Outputs: ab3af8566ddd20d7efc9b314abe90755 Node.js v6.1.0 Outputs: 07625e142e4ac5961de57472657a88c1 Question I was wondering what causes that in new version and how can I solve this? Update Similar issues on GitHub: https://github.com/nodejs

Node.js and crypto library

随声附和 提交于 2019-11-27 15:17:16
问题 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 = cipher.final('hex') var decipher = crypto.createDecipher('aes-256-cbc','InmbuvP6Z8') decipher.update(crypted,'hex','utf8') var dec = decipher.final('utf8') When I do console.log(dec), it's null. For some reason if I set test to "123|123123", it works. So why does