Skip to content

Commit 75431f4

Browse files
committed
pull out aes
1 parent 8796866 commit 75431f4

File tree

3 files changed

+37
-5
lines changed

3 files changed

+37
-5
lines changed

index.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,23 @@ exports.getHashes = function () {
4141
var p = require('./pbkdf2')(exports)
4242
exports.pbkdf2 = p.pbkdf2
4343
exports.pbkdf2Sync = p.pbkdf2Sync
44-
require('browserify-aes/inject')(exports, module.exports);
44+
45+
var aes = require('browserify-aes');
46+
[
47+
'Cipher',
48+
'createCipher',
49+
'Cipheriv',
50+
'createCipheriv',
51+
'Decipher',
52+
'createDecipher',
53+
'Decipheriv',
54+
'createDecipheriv',
55+
'getCiphers',
56+
'listCiphers'
57+
].forEach(function (key) {
58+
exports[key] = aes[key];
59+
})
60+
4561
require('browserify-sign/inject')(module.exports, exports);
4662
require('diffie-hellman/inject')(exports, module.exports);
4763
require('create-ecdh/inject')(module.exports, exports);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"node": "*"
1717
},
1818
"dependencies": {
19-
"browserify-aes": "0.8.1",
19+
"browserify-aes": "^1.0.0",
2020
"browserify-sign": "2.8.0",
2121
"create-ecdh": "1.0.3",
2222
"create-hash": "^1.1.0",

test/aes.js

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
var test = require('tape');
2-
var crypto = require('../');
2+
var crypto = require('browserify-aes/browser');
3+
var randomBytes = require('randombytes');
34
test('ciphers', function (t) {
45
crypto.listCiphers().forEach(function (cipher) {
56
t.test(cipher, function (t) {
67
t.plan(1);
7-
var data = crypto.randomBytes(562);
8-
var password = crypto.randomBytes(20);
8+
var data = randomBytes(562);
9+
var password = randomBytes(20);
910
var crypter = crypto.createCipher(cipher, password);
1011
var decrypter = crypto.createDecipher(cipher, password);
1112
var out = [];
@@ -22,4 +23,19 @@ test('ciphers', function (t) {
2223
test('getCiphers', function (t) {
2324
t.plan(1);
2425
t.ok(crypto.getCiphers().length, 'get ciphers returns an array');
26+
});
27+
test('through crypto browserify works', function (t) {
28+
t.plan(2);
29+
var crypto = require('../');
30+
var cipher = 'aes-128-ctr';
31+
var data = randomBytes(562);
32+
var password = randomBytes(20);
33+
var crypter = crypto.createCipher(cipher, password);
34+
var decrypter = crypto.createDecipher(cipher, password);
35+
var out = [];
36+
out.push(decrypter.update(crypter.update(data)));
37+
out.push(decrypter.update(crypter.final()));
38+
out.push(decrypter.final());
39+
t.equals(data.toString('hex'), Buffer.concat(out).toString('hex'));
40+
t.ok(crypto.getCiphers().length, 'get ciphers returns an array');
2541
});

0 commit comments

Comments
 (0)