-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathedSingleFiles.js
36 lines (30 loc) · 1.12 KB
/
edSingleFiles.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
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 key = "yourSecretKey";
const filePath = "data/test.txt";
// Encrypt the file using the provided mainKey
const encryptedData = temcrypt.encrypt({
dataFiles: filePath,
mainKey: key
});
// Return Encrypted file
console.log("------- Encrypt Single File -------");
console.log("Encrypted File:", encryptedData.encryptedData[0].fileName);
console.log("Time Key:", encryptedData.encryptedData[0].timeKey);
console.log("---");
// Decrypt the encrypted file using the same mainKey
const decryptedData = temcrypt.decrypt({
dataFiles: encryptedData.encryptedData[0].fileName,
mainKey: key
});
// Return Decrypted file
console.log("------- Decrypt Single File -------");
console.log("Decrypted File:", decryptedData.decryptedData[0].dataString);
console.log("Creation Date:", decryptedData.decryptedData[0].creationDate);
console.log("Last Decryption Date:", decryptedData.decryptedData[0].lastDecryptionDate);