change encryption to work on hex strings

..instead of binary, to work around an issue with bitcore/sjcl. I'm not sure
what the issue is exactly, except that encryption of binary data isn't working
correctly due to some kind of string stuff involving decodeURIComponent inside
sjcl. I haven't fully figured it out. For now I am changing the network
protocol to hex to workaround the issue.

See this: https://github.com/bitpay/bitcore/pull/416
This commit is contained in:
Ryan X. Charles 2014-07-09 01:13:42 -07:00
parent 88ab38eb00
commit 643cad3a39
2 changed files with 6 additions and 3 deletions

View File

@ -21,7 +21,8 @@ Message.encode = function(topubkey, fromkey, payload, opts) {
}
var toencrypt = Buffer.concat([version1, version2, nonce, payload]);
var encrypted = Message._encrypt(topubkey, toencrypt);
var toencrypthexbuf = new Buffer(toencrypt.toString('hex')); //due to bug in sjcl/bitcore, must use hex string
var encrypted = Message._encrypt(topubkey, toencrypthexbuf);
var sig = Message._sign(fromkey, encrypted);
var encoded = {
pubkey: fromkey.public.toString('hex'),
@ -63,7 +64,8 @@ Message.decode = function(key, encoded, opts) {
}
try {
var decrypted = Message._decrypt(key.private, encrypted);
var decryptedhexbuf = Message._decrypt(key.private, encrypted);
var decrypted = new Buffer(decryptedhexbuf.toString(), 'hex'); //workaround for bug in bitcore/sjcl
} catch (e) {
throw new Error('Cannot decrypt data: ' + e);
}

View File

@ -100,7 +100,8 @@ describe('Message model', function() {
var version2 = new Buffer([0]);
var nonce = new Buffer([0, 0, 0, 0, 0, 0, 0, 0]);
var toencrypt = Buffer.concat([version1, version2, nonce, payload]);
var encrypted = Message._encrypt(topubkey, toencrypt);
var toencrypt_workaround = new Buffer(toencrypt.toString('hex'));
var encrypted = Message._encrypt(topubkey, toencrypt_workaround);
var sig = Message._sign(fromkey, encrypted);
var encoded = {
pubkey: fromkey.public.toString('hex'),