Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

created custom encrypt and decrypt function #19

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed server/encrypted/app.png
Binary file not shown.
Binary file added server/public/3rd sem syllabus.pdf
Binary file not shown.
Binary file added server/public/Learning gimp.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added server/public/input box.mp4
Binary file not shown.
118 changes: 79 additions & 39 deletions server/routes/download.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ const User = require('../models/user')
const { create } = require("ipfs-http-client");
const path = require('path')

const {decryptFile} = require('../utils/storzcrypt')

const magic = new Magic(process.env.MAGIC_SECRET_KEY);

const projectId = process.env.INFURA_PROJECT_ID;
Expand Down Expand Up @@ -111,47 +113,85 @@ router.get("/api/download/:cid", async (req, res) => {
const fileName = file.files[0].file_name;
const encryptedPath = '../server/encrypted/' + fileName;
const decryptedPath = '../server/public/' + fileName;
await getFile(cid, encryptedPath).then(async() => {
try {
jscrypt.decryptFile(
encryptedPath,
decryptedPath,
"aes256",
file.encryption_key,
655000,
(isDone) => {
if (isDone === true) {
console.log(fileName + ' is decrypted successfully!');
console.log("Sending files to the user");
//send the file to the client
res.sendFile(path.resolve(decryptedPath));

setTimeout(() => {
unlink(decryptedPath, (err) => {
if (err) {
console.log(err);
}
console.log(decryptedPath + ' is deleted!');
})

unlink(encryptedPath, (err) => {
if (err) {
console.log(err);
}
console.log(encryptedPath + ' is deleted!');
})
}, 2 * 60 * 1000)
}
else {
console.log("File decryption in progress...");
}

await getFile(cir, encryptedPath).then(async () => {
await decryptFile(
encryptedPath,
decryptedPath,
"aes256",
file.encryption_key,
655000,
(isDone) => {
if (isDone === true) {
console.log(fileName + ' is decrypted successfully!');
console.log("Sending files to the user");
//send the file to the client
res.sendFile(path.resolve(decryptedPath));

setTimeout(() => {
unlink(decryptedPath, (err) => {
if (err) {
console.log(err);
}
console.log(decryptedPath + ' is deleted!');
})

unlink(encryptedPath, (err) => {
if (err) {
console.log(err);
}
console.log(encryptedPath + ' is deleted!');
})
}, 2 * 60 * 1000)
}
)
} catch (err) {
console.log(err);
return res.status(500).json({ error: err.message });
}
else {
console.log("File decryption in progress...");
}
}
)
})

// await getFile(cid, encryptedPath).then(async() => {
// try {
// jscrypt.decryptFile(
// encryptedPath,
// decryptedPath,
// "aes256",
// file.encryption_key,
// 655000,
// (isDone) => {
// if (isDone === true) {
// console.log(fileName + ' is decrypted successfully!');
// console.log("Sending files to the user");
// //send the file to the client
// res.sendFile(path.resolve(decryptedPath));

// setTimeout(() => {
// unlink(decryptedPath, (err) => {
// if (err) {
// console.log(err);
// }
// console.log(decryptedPath + ' is deleted!');
// })

// unlink(encryptedPath, (err) => {
// if (err) {
// console.log(err);
// }
// console.log(encryptedPath + ' is deleted!');
// })
// }, 2 * 60 * 1000)
// }
// else {
// console.log("File decryption in progress...");
// }
// }
// )
// } catch (err) {
// console.log(err);
// return res.status(500).json({ error: err.message });
// }
// })
} else {
return res.status(200).sendFile("../private/hacker.png", { root: __dirname });
}
Expand Down
Loading