-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtaskController.js
More file actions
19 lines (15 loc) · 910 Bytes
/
Copy pathtaskController.js
File metadata and controls
19 lines (15 loc) · 910 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// taskController.js
const CryptoJS = require("crypto-js");
//const SECRET_KEY = "Add_Secret_Key_Here"; // Comment out if you don't want to use env file
const SECRET_KEY = process.env.ENCRYPTION_KEY;
// Encrypt before saving
const encryptedtitle = CryptoJS.AES.encrypt(task.title, SECRET_KEY).toString();
const encryptedDescription = CryptoJS.AES.encrypt(task.description, SECRET_KEY).toString();
const encryptedDueDateTime = CryptoJS.AES.encrypt(task.dueDateTime, SECRET_KEY).toString();
// Decrypt when retrieving
const bytes = CryptoJS.AES.decrypt(encryptedtitle, SECRET_KEY);
const decryptedtitle = bytes.toString(CryptoJS.enc.Utf8);
const bytes = CryptoJS.AES.decrypt(encryptedDescription, SECRET_KEY);
const decryptedDescription = bytes.toString(CryptoJS.enc.Utf8);
const bytes = CryptoJS.AES.decrypt(encryptedDueDateTime, SECRET_KEY);
const decryptedDueDateTime = bytes.toString(CryptoJS.enc.Utf8);