Thijs Koerselman
2013-06-27 13:57:53 UTC
Hi,
I'm trying to encrypt some string in C#, send it to a Node server and
decrypt it there. I am having a hard time because I keep getting this error:
TypeError: error:06065064:digital envelope routines:EVP_DecryptFinal_ex:bad
decrypt
at Decipher.Cipher.final (crypto.js:257:27)
I have tried different AES modes and key sizes but it didn't help. Just for
testing I'm sending a json post to the server containing base64 encoded
versions of key, iv and the encrypted string (fingerprint in this example).
In the post request handler I do this:
var crypto = require('crypto');
var key = req.body.key;
var iv = req.body.iv;
var binkey = new Buffer(key, 'base64');
var biniv = new Buffer(iv, 'base64');
var crypted = req.body.fingerprint;
var bincrypted = new Buffer(crypted, 'base64');
var decipher = crypto.createDecipher('aes-256-cbc',binkey, biniv);
var dec = decipher.update(bincrypted,'binary','utf8');
dec += decipher.final('utf8');
console.log("dec", dec);
To be sure I'm using the same Aes mode and padding on the encryption this
is what's reported by my C# Aes, including the JSON being sent.
Keysize 256
Mode CBC
Padding PKCS7
Key: YJAG4xYTTQ0Ke3FBIDgmobERgbi/Tl/LYt9cNmt5w0g=
IV :VUdInSdIlCLS/D3AbXhhnQ==
json: {
"fingerprint" : "a7pNFC3Bnac7Y/k7/b+b4jHdH5CE/nbu23Mmj9pAhZw=",
"key" : "YJAG4xYTTQ0Ke3FBIDgmobERgbi/Tl/LYt9cNmt5w0g=",
"iv" : "VUdInSdIlCLS/D3AbXhhnQ=="
}
Am I overlooking something maybe?
--
--
Job Board: http://jobs.nodejs.org/
Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to nodejs-/***@public.gmane.org
To unsubscribe from this group, send email to
nodejs+unsubscribe-/***@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
---
You received this message because you are subscribed to the Google Groups "nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.
I'm trying to encrypt some string in C#, send it to a Node server and
decrypt it there. I am having a hard time because I keep getting this error:
TypeError: error:06065064:digital envelope routines:EVP_DecryptFinal_ex:bad
decrypt
at Decipher.Cipher.final (crypto.js:257:27)
I have tried different AES modes and key sizes but it didn't help. Just for
testing I'm sending a json post to the server containing base64 encoded
versions of key, iv and the encrypted string (fingerprint in this example).
In the post request handler I do this:
var crypto = require('crypto');
var key = req.body.key;
var iv = req.body.iv;
var binkey = new Buffer(key, 'base64');
var biniv = new Buffer(iv, 'base64');
var crypted = req.body.fingerprint;
var bincrypted = new Buffer(crypted, 'base64');
var decipher = crypto.createDecipher('aes-256-cbc',binkey, biniv);
var dec = decipher.update(bincrypted,'binary','utf8');
dec += decipher.final('utf8');
console.log("dec", dec);
To be sure I'm using the same Aes mode and padding on the encryption this
is what's reported by my C# Aes, including the JSON being sent.
Keysize 256
Mode CBC
Padding PKCS7
Key: YJAG4xYTTQ0Ke3FBIDgmobERgbi/Tl/LYt9cNmt5w0g=
IV :VUdInSdIlCLS/D3AbXhhnQ==
json: {
"fingerprint" : "a7pNFC3Bnac7Y/k7/b+b4jHdH5CE/nbu23Mmj9pAhZw=",
"key" : "YJAG4xYTTQ0Ke3FBIDgmobERgbi/Tl/LYt9cNmt5w0g=",
"iv" : "VUdInSdIlCLS/D3AbXhhnQ=="
}
Am I overlooking something maybe?
--
--
Job Board: http://jobs.nodejs.org/
Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to nodejs-/***@public.gmane.org
To unsubscribe from this group, send email to
nodejs+unsubscribe-/***@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
---
You received this message because you are subscribed to the Google Groups "nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.