-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
41 lines (25 loc) · 1.25 KB
/
test.js
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
const zest = require("./index.js");
const key = new zest.EncryptionKey();
const testString = "Moniker Zest Encryption Test"
console.log("Testing encryption/decryption");
const encrypted = key.encrypt(testString);
const decrypted = key.decrypt(encrypted);
if (decrypted === testString) {
console.log("Encryption/decryption test passed using test string: \"" + testString + "\"");
}
console.log("Testing key export/import");
const exportedKey = key.export();
const prevKeyId = key.id;
key.import(exportedKey);
if (key.decrypt(encrypted) === testString) {
console.log("Key export/import test passed using test string: \"" + testString + "\"");
}
console.log("Testing default key importing");
const loadedKey = new zest.EncryptionKey(exportedKey);
if (loadedKey.decrypt(encrypted) === testString) {
console.log("Default key import test passed using test string: \"" + testString + "\"");
}
console.log("Key ID test", (loadedKey.id === prevKeyId ? "passed" : "failed"), `using key ID: ${loadedKey.id}`);
const validVerify = key.verify("Test Message", (key.sign("Test Message")));
const invalidVerify = key.verify("Test Message", (key.sign("Different Message")));
console.log("Message signing test", (validVerify && !invalidVerify) ? "passed" : "failed");