-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathedMultipleFilesDifferentKeys.js
48 lines (42 loc) · 1.61 KB
/
edMultipleFilesDifferentKeys.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
let temcrypt;
try {
// Try to import the installed version of temcrypt
temcrypt = require('temcrypt');
} catch (error) {
// If the library is not installed, use the local version
temcrypt = require('./../../temcrypt');
}
const filesToEncrypt = [
{ filePath: "data/test1.txt", key: "key1" },
{ filePath: "data/test2.txt", key: "key2" },
{ filePath: "data/test3.txt", key: "key3" },
];
// Encrypt the files using different keys for each file
const encryptedData = filesToEncrypt.map((fileData) => {
return temcrypt.encrypt({
dataFiles: [fileData.filePath],
mainKey: fileData.key,
});
});
console.log("------- Encrypt Multiple Files with Different Keys -------");
encryptedData.forEach((fileData, index) => {
console.log("Encrypted File:", fileData.encryptedData[0].fileName);
console.log("Time Key:", fileData.encryptedData[0].timeKey);
console.log("Key Used:", filesToEncrypt[index].key);
console.log("---");
});
// Decrypt the encrypted files using the corresponding keys
const decryptedData = encryptedData.map((fileData, index) => {
return temcrypt.decrypt({
dataString: fileData.encryptedData[0].dataString,
mainKey: filesToEncrypt[index].key,
});
});
console.log("------- Decrypt Multiple Files with Different Keys -------");
decryptedData.forEach((fileData, index) => {
console.log("Decrypted File:", fileData.dataString);
console.log("Creation Date:", fileData.creationDate);
console.log("Last Decryption Date:", fileData.lastDecryptionDate);
console.log("Key Used:", filesToEncrypt[index].key);
console.log("---");
});