Skip to content

Commit b76e10b

Browse files
author
Herman White
committed
Switched crypto program
1 parent fe4816a commit b76e10b

File tree

3 files changed

+31
-19
lines changed

3 files changed

+31
-19
lines changed

package-lock.json

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
"dependencies": {
1313
"basic-ftp": "^4.5.3",
1414
"cors": "^2.8.5",
15-
"crypto-js": "^4.0.0",
1615
"dotenv": "^8.2.0",
1716
"express": "^4.17.1",
18-
"nodemon": "^2.0.2"
17+
"nodemon": "^2.0.2",
18+
"simple-crypto-js": "^2.2.0"
1919
}
2020
}

server.js

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@ require("dotenv").config();
33
const cors = require("cors");
44
const ftp = require("basic-ftp");
55
const CryptoJS = require("crypto-js");
6+
var SimpleCrypto = require("simple-crypto-js").default;
67

78
const PORT = process.env.PORT || 3000;
89

10+
// playground end
11+
912
const app = express();
1013
app.use(express.json()); // for parsing application/json
1114
app.use(cors());
@@ -25,22 +28,17 @@ const clients = {};
2528
// basic-ftp
2629

2730
app.post("/navigate", (req, res) => {
28-
if (req.body && req.body.ciphertext) {
31+
if (req.body && req.body.cipherText) {
2932
init();
3033

3134
async function init() {
32-
const { ciphertext } = req.body;
33-
// decrypt data received from frontend
34-
console.log("Ciphertext:", ciphertext);
35-
const bytes = CryptoJS.AES.decrypt(ciphertext, process.env.PASSWORD);
36-
console.log("Bytes:", bytes);
37-
38-
console.log("CryptoJS keys:", Object.keys(CryptoJS).length);
39-
console.log("Decrypteddata:", bytes.toString(CryptoJS.enc.Utf8));
35+
const { cipherText } = req.body;
4036

41-
var decryptedData = JSON.parse(bytes.toString(CryptoJS.enc.Utf8));
37+
// decrypt data received from frontend
38+
var simpleCrypto = new SimpleCrypto(process.env.PASSWORD);
39+
var decipherText = simpleCrypto.decrypt(cipherText);
4240

43-
const { ftpHost, ftpUser, ftpPassword, path } = decryptedData;
41+
const { ftpHost, ftpUser, ftpPassword, path } = JSON.parse(decipherText);
4442

4543
// if user is found and logged in
4644
if (
@@ -97,20 +95,19 @@ app.post("/navigate", (req, res) => {
9795

9896
// removes and disconnects client
9997
app.post("/disconnect", (req, res) => {
100-
if (req.body && req.body.ciphertext) {
98+
if (req.body && req.body.cipherText) {
10199
} else {
102100
res.status(400).send("Unauthorized access.");
103101
}
104102

105103
const init = async () => {
106-
const { ciphertext } = req.body;
104+
const { cipherText } = req.body;
107105

108106
// decrypt data received from frontend
109-
const bytes = CryptoJS.AES.decrypt(ciphertext, process.env.PASSWORD);
110-
111-
var decryptedData = JSON.parse(bytes.toString(CryptoJS.enc.Utf8));
107+
var simpleCrypto = new SimpleCrypto(process.env.PASSWORD);
108+
var decipherText = simpleCrypto.decrypt(cipherText);
112109

113-
const { ftpUser } = decryptedData;
110+
const { ftpUser } = JSON.parse(decipherText);
114111

115112
if (
116113
clients[ftpUser] !== undefined &&

0 commit comments

Comments
 (0)