Skip to content

Commit

Permalink
Merge pull request #34 from gordonwritescode/master
Browse files Browse the repository at this point in the history
Replace base58-native with bs58 in encrypt/decrypt
  • Loading branch information
martindale committed Feb 3, 2015
2 parents 1e89b20 + 4d2404c commit 8a039f2
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
4 changes: 2 additions & 2 deletions lib/decrypt.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
var base58 = require('base58-native');
var base58 = require('bs58');
var crypto = require('crypto');

module.exports = function decrypt(password, str) {
var aes256 = crypto.createDecipher('aes-256-cbc', password);
var a = aes256.update(base58.decode(str));
var a = aes256.update(new Buffer(base58.decode(str)));
var b = aes256.final();
var buf = new Buffer(a.length + b.length);

Expand Down
4 changes: 2 additions & 2 deletions lib/encrypt.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var base58 = require('base58-native');
var base58 = require('bs58');
var crypto = require('crypto');

module.exports = function encrypt(password, str) {
Expand All @@ -9,6 +9,6 @@ module.exports = function encrypt(password, str) {

a.copy(buf, 0);
b.copy(buf, a.length);

return base58.encode(buf);
};
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
"bs58": "^2.0.0",
"request": "^2.36.0",
"express": "^4.3.1",
"base58-native": "^0.1.4",
"body-parser": "^1.2.0"
},
"devDependencies": {
Expand Down
11 changes: 10 additions & 1 deletion test/test.bitauth.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ describe('bitauth', function() {
var contract = 'keyboard cat';
var secret = 'o hai, nsa. how i do teh cryptos?';
var password = 's4705hiru13z!';

var encryptedSecret = '291Dm9unZMwfxBA7BEHiQsraRxCrMRqwJ2TjCWwEH3Sp5QGMehNFNgZLo62sgF5Khe';

// signature from generate keys
var signature = null;
var enc = null;
Expand Down Expand Up @@ -177,6 +178,14 @@ describe('bitauth', function() {
it('should decrypt the secret message', function(done) {
var dec = bitauth.decrypt(password, enc);
should.exist(dec);
dec.should.equal(secret);
done();
});

it('should decrypt a previously known message', function(done) {
var dec = bitauth.decrypt(password, encryptedSecret);
should.exist(dec);
dec.should.equal(secret);
done();
});

Expand Down

0 comments on commit 8a039f2

Please sign in to comment.