* Encrypts a file and replaces the original with the encrypted version * @param {string} filePath - Path to the file to encrypt * @returns {Promise } - Path to the encrypted file
(filePath)
| 9 | * @returns {Promise<string>} - Path to the encrypted file |
| 10 | */ |
| 11 | async function encryptFile(filePath) { |
| 12 | try { |
| 13 | // Read the file |
| 14 | const fileContent = await fs.readFile(filePath); |
| 15 | |
| 16 | // Encrypt the content |
| 17 | const encryptedContent = encrypt(fileContent.toString("base64")); |
| 18 | |
| 19 | // Write the encrypted content back to the file |
| 20 | await fs.writeFile(filePath, encryptedContent); |
| 21 | |
| 22 | return filePath; |
| 23 | } catch (error) { |
| 24 | console.error(`Error encrypting file ${filePath}:`, error); // oxlint-disable-line no-console |
| 25 | throw error; |
| 26 | } |
| 27 | } |
| 28 | |
| 29 | /** |
| 30 | * Decrypts a file and returns the content |
no test coverage detected