Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
80538 views
1
var test = require('tape');
2
var crypto = require('browserify-aes/browser');
3
var randomBytes = require('randombytes');
4
test('ciphers', function (t) {
5
crypto.listCiphers().forEach(function (cipher) {
6
t.test(cipher, function (t) {
7
t.plan(1);
8
var data = randomBytes(562);
9
var password = randomBytes(20);
10
var crypter = crypto.createCipher(cipher, password);
11
var decrypter = crypto.createDecipher(cipher, password);
12
var out = [];
13
out.push(decrypter.update(crypter.update(data)));
14
out.push(decrypter.update(crypter.final()));
15
if (cipher.indexOf('gcm') > -1) {
16
decrypter.setAuthTag(crypter.getAuthTag());
17
}
18
out.push(decrypter.final());
19
t.equals(data.toString('hex'), Buffer.concat(out).toString('hex'));
20
});
21
});
22
});
23
test('getCiphers', function (t) {
24
t.plan(1);
25
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');
41
});
42