vanilla.js
1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
"use strict";
const crypto = require('crypto');
let secret = "squirrel", kruptein,
ciphers = [], hashes = [],
encoding = ['binary', 'hex', 'base64'],
phrases = [
"Secret Squirrel",
"écureuil secret",
"गुप्त गिलहरी",
"ਗੁਪਤ ਗਿੱਠੀ",
"veverița secretă",
"секретная белка",
"leyndur íkorna",
"السنجاب السري",
"գաղտնի սկյուռ",
"feòrag dìomhair",
"গোপন কাঠবিড়ালি",
"秘密のリス",
"таемная вавёрка",
];
const options = {
use_scrypt: true,
use_asn1: true
};
// Filter getCiphers()
ciphers = crypto.getCiphers().filter(cipher => {
if (cipher.match(/^aes/i) && cipher.match(/256/i)&& !cipher.match(/hmac|wrap|ccm|ecb/))
return cipher;
});
// Filter getHashes()
hashes = crypto.getHashes().filter(hash => {
if (hash.match(/^sha[2-5]/i) && !hash.match(/rsa/i))
return hash;
});
// Because we want a quick test
//ciphers=["aes-256-gcm"];
//hashes=["sha512"];
for (let cipher in ciphers) {
options.algorithm = ciphers[cipher];
for (let hash in hashes) {
options.hashing = hashes[hash];
for (let enc in encoding) {
options.encodeas = encoding[enc];
kruptein = require("../index.js")(options);
console.log('kruptein: { algorithm: "'+options.algorithm+'", hashing: "'+options.hashing+'", encodeas: "'+options.encodeas+'" }');
let ct, pt;
for (let phrase in phrases) {
console.log(phrases[phrase])
kruptein.set(secret, phrases[phrase], (err, res) => {
if (err)
console.log(err);
ct = res;
});
console.log(JSON.stringify(ct));
kruptein.get(secret, ct, (err, res) => {
if (err)
console.log(err);
pt = res;
});
console.log(pt);
console.log("");
}
}
}
}