-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
112 lines (82 loc) · 4.65 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
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
//const openpgp = require('openpgp');
const process = require('process');
const securePGPstorage = require('./index.js');
process.stdout.write('\x1Bc');
console.log('\x1b[1m%s\x1b[0m', 'Starting testing...\n');
sPGPs = new securePGPstorage();
(async () => {
console.log('\x1b[1m%s\x1b[0m', '1. Create storage');
console.log('////////////////////////////////////////////////////////////');
await sPGPs.createStorage('John Smith', 'john.smith@gmail.com', '1q2w3e4r5t6y7u8i9o0p');
console.log('Nickname:', sPGPs.nickname);
console.log('E-mail:', sPGPs.email);
console.log('Fingerprint:', sPGPs.fingerprint);
console.log('Public key:');
console.log(sPGPs.publicKeyArmored);
console.log('////////////////////////////////////////////////////////////\n\n\n');
console.log('\x1b[1m%s\x1b[0m', '2. Checking the activity of all data in the storage');
console.log('////////////////////////////////////////////////////////////');
console.log('All data is activated:', await sPGPs.checkAllData());
console.log('////////////////////////////////////////////////////////////\n\n\n');
console.log('\x1b[1m%s\x1b[0m', '3. Encrypt String data with PGP keys');
console.log('////////////////////////////////////////////////////////////');
const recipientPublicKeyArmored = sPGPs.publicKeyArmored;
let encrypted = await sPGPs.encryptMessage('Hello world!', recipientPublicKeyArmored, true);
console.log('Encrypted message:');
console.log(encrypted);
console.log('Check message:', await sPGPs.checkMessage(encrypted));
console.log('////////////////////////////////////////////////////////////\n\n\n');
console.log('\x1b[1m%s\x1b[0m', '4. Decrypt String data with PGP keys');
console.log('////////////////////////////////////////////////////////////');
const senderPublicKeyArmored = sPGPs.publicKeyArmored;
let decrypted = await sPGPs.decryptMessage(encrypted, senderPublicKeyArmored);
console.log('Decrypted message:');
console.log(decrypted);
console.log(decrypted.data);
console.log(decrypted.signatures[0].keyID.toHex());
console.log(sPGPs.fingerprint);
await decrypted.signatures[0].verified;
console.log('////////////////////////////////////////////////////////////\n\n\n');
console.log('\x1b[1m%s\x1b[0m', '5. Encrypt symmetrically with compression');
console.log('////////////////////////////////////////////////////////////');
encrypted = await sPGPs.encryptMessageSymmetricallyWithCompression('Hello again!', '1234567890');
console.log('Encrypted message:');
console.log(encrypted);
console.log('Check message:', await sPGPs.checkMessage(encrypted));
console.log('////////////////////////////////////////////////////////////\n\n\n');
console.log('\x1b[1m%s\x1b[0m', '6. Decrypt symmetrically with compression');
console.log('////////////////////////////////////////////////////////////');
decrypted = await sPGPs.decryptMessageSymmetricallyWithCompression(encrypted, '1234567890');
console.log('Decrypted message:');
console.log(decrypted);
console.log('////////////////////////////////////////////////////////////\n\n\n');
console.log('\x1b[1m%s\x1b[0m', '7. Storage encryption');
console.log('////////////////////////////////////////////////////////////');
const encryptedStorage = await sPGPs.encryptStorage();
console.log('Encrypted storage:');
console.log(encryptedStorage);
console.log('Check message:', await sPGPs.checkMessage(encryptedStorage));
console.log('encodeURIComponent (for file href html):', await sPGPs.generateSecureFile());
console.log('////////////////////////////////////////////////////////////\n\n\n');
console.log('\x1b[1m%s\x1b[0m', '8. Clearing data from storage');
console.log('////////////////////////////////////////////////////////////');
await sPGPs.eraseAllData();
console.log('Nickname:', sPGPs.nickname);
console.log('E-mail:', sPGPs.email);
console.log('Fingerprint:', sPGPs.fingerprint);
console.log('Public key:');
console.log(sPGPs.publicKeyArmored);
console.log('All data is activated:', await sPGPs.checkAllData());
console.log('////////////////////////////////////////////////////////////\n\n\n');
console.log('\x1b[1m%s\x1b[0m', '9. Storage decryption');
console.log('////////////////////////////////////////////////////////////');
const decryptedStorage = await sPGPs.decryptStorage(encryptedStorage, '1q2w3e4r5t6y7u8i9o0p');
console.log('Decrypted storage:', decryptedStorage);
console.log('Nickname:', sPGPs.nickname);
console.log('E-mail:', sPGPs.email);
console.log('Fingerprint:', sPGPs.fingerprint);
console.log('Public key:');
console.log(sPGPs.publicKeyArmored);
console.log('All data is activated:', await sPGPs.checkAllData());
console.log('////////////////////////////////////////////////////////////\n\n\n');
})();