react / react-0.13.3 / examples / basic-commonjs / node_modules / browserify / node_modules / crypto-browserify / test / aes.js
80728 viewsvar test = require('tape');1var crypto = require('browserify-aes/browser');2var randomBytes = require('randombytes');3test('ciphers', function (t) {4crypto.listCiphers().forEach(function (cipher) {5t.test(cipher, function (t) {6t.plan(1);7var data = randomBytes(562);8var password = randomBytes(20);9var crypter = crypto.createCipher(cipher, password);10var decrypter = crypto.createDecipher(cipher, password);11var out = [];12out.push(decrypter.update(crypter.update(data)));13out.push(decrypter.update(crypter.final()));14if (cipher.indexOf('gcm') > -1) {15decrypter.setAuthTag(crypter.getAuthTag());16}17out.push(decrypter.final());18t.equals(data.toString('hex'), Buffer.concat(out).toString('hex'));19});20});21});22test('getCiphers', function (t) {23t.plan(1);24t.ok(crypto.getCiphers().length, 'get ciphers returns an array');25});26test('through crypto browserify works', function (t) {27t.plan(2);28var crypto = require('../');29var cipher = 'aes-128-ctr';30var data = randomBytes(562);31var password = randomBytes(20);32var crypter = crypto.createCipher(cipher, password);33var decrypter = crypto.createDecipher(cipher, password);34var out = [];35out.push(decrypter.update(crypter.update(data)));36out.push(decrypter.update(crypter.final()));37out.push(decrypter.final());38t.equals(data.toString('hex'), Buffer.concat(out).toString('hex'));39t.ok(crypto.getCiphers().length, 'get ciphers returns an array');40});4142