diff --git a/lib/decrypt.js b/lib/decrypt.js index 87fe9c9..6f35819 100644 --- a/lib/decrypt.js +++ b/lib/decrypt.js @@ -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); diff --git a/lib/encrypt.js b/lib/encrypt.js index ec40873..beb3243 100644 --- a/lib/encrypt.js +++ b/lib/encrypt.js @@ -1,4 +1,4 @@ -var base58 = require('base58-native'); +var base58 = require('bs58'); var crypto = require('crypto'); module.exports = function encrypt(password, str) { @@ -9,6 +9,6 @@ module.exports = function encrypt(password, str) { a.copy(buf, 0); b.copy(buf, a.length); - + return base58.encode(buf); }; diff --git a/package.json b/package.json index eefd2f9..c244ed5 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/test/test.bitauth.js b/test/test.bitauth.js index 037c228..607d6e5 100644 --- a/test/test.bitauth.js +++ b/test/test.bitauth.js @@ -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; @@ -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(); });