11var test = require ( 'tape' ) ;
2- var crypto = require ( '../' ) ;
2+ var crypto = require ( 'browserify-aes/browser' ) ;
3+ var randomBytes = require ( 'randombytes' ) ;
34test ( '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) {
2223test ( '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