diff --git a/.env b/.env new file mode 100644 index 0000000..63b0db7 --- /dev/null +++ b/.env @@ -0,0 +1,2 @@ +APPLICATION_HOSTNAME="127.0.0.1" +APPLICATION_PORT=3000 \ No newline at end of file diff --git a/Crypto/AES/decryptAES.js b/Crypto/AES/decryptAES.js deleted file mode 100644 index 12b036a..0000000 --- a/Crypto/AES/decryptAES.js +++ /dev/null @@ -1,8 +0,0 @@ -const CryptoJS = require("crypto-js"); - -const decryptAES = ((decryptMessage, secretKey) => { - let decrypted = CryptoJS.AES.decrypt(decryptMessage, secretKey).toString(CryptoJS.enc.Utf8); - return decrypted; -}); - -module.exports = decryptAES; \ No newline at end of file diff --git a/Crypto/AES/decryptingAES.js b/Crypto/AES/decryptingAES.js deleted file mode 100644 index d5d0cdb..0000000 --- a/Crypto/AES/decryptingAES.js +++ /dev/null @@ -1,15 +0,0 @@ -const fs = require('fs'); -const { parse } = require("csv-parse"); -const decryptAES = require('./decryptAES'); -const writeFile = require('../../Files/writeFile'); - -const decryptingAES = (({pathIn, pathOut, secretKey}) => { - fs.createReadStream(pathIn) - .pipe(parse({ delimiter: ",", from_line: 1 })) - .on("data", (line) => { - const dencrypt = decryptAES( line[0], secretKey); - writeFile(pathOut, dencrypt); - }); -}); - -module.exports = decryptingAES; \ No newline at end of file diff --git a/Crypto/AES/encryptAES.js b/Crypto/AES/encryptAES.js deleted file mode 100644 index 3908182..0000000 --- a/Crypto/AES/encryptAES.js +++ /dev/null @@ -1,8 +0,0 @@ -const CryptoJS = require("crypto-js"); - -const encryptAES = ((encryptMessage, secretKey) => { - let encrypted = CryptoJS.AES.encrypt(encryptMessage, secretKey); - return encrypted; -}); - -module.exports = encryptAES; \ No newline at end of file diff --git a/Crypto/AES/encryptingAES.js b/Crypto/AES/encryptingAES.js deleted file mode 100644 index ea24f38..0000000 --- a/Crypto/AES/encryptingAES.js +++ /dev/null @@ -1,15 +0,0 @@ -const fs = require('fs'); -const { parse } = require("csv-parse"); -const encryptAES = require('./encryptAES'); -const writeFile = require('../../Files/writeFile'); - -const encryptingAES = (({pathIn, pathOut, secretKey}) => { - fs.createReadStream(pathIn) - .pipe(parse({ delimiter: ",", from_line: 1 })) - .on("data", (line) => { - const encrypt = encryptAES( line[0], secretKey); - writeFile(pathOut, encrypt); - }); -}); - -module.exports = encryptingAES; \ No newline at end of file diff --git a/Crypto/Base64/encodeBase64.js b/Crypto/Base64/encodeBase64.js deleted file mode 100644 index 864bdf5..0000000 --- a/Crypto/Base64/encodeBase64.js +++ /dev/null @@ -1,8 +0,0 @@ -const CryptoJS = require("crypto-js"); - -const encodeBase64 = ((encodeMessage) => { - let encode = encodeMessage.toString(CryptoJS.enc.Base64); - return encode; -}); - -module.exports = encodeBase64; \ No newline at end of file diff --git a/Crypto/Base64/encodingBase64.js b/Crypto/Base64/encodingBase64.js deleted file mode 100644 index 3c4b4d3..0000000 --- a/Crypto/Base64/encodingBase64.js +++ /dev/null @@ -1,15 +0,0 @@ -const fs = require('fs'); -const { parse } = require("csv-parse"); -const encodeBase64 = require('./encodeBase64'); -const writeFile = require('../../Files/writeFile'); - -const encodingBase64 = (({pathIn, pathOut}) => { - fs.createReadStream(pathIn) - .pipe(parse({ delimiter: ",", from_line: 1 })) - .on("data", (line) => { - const encode = encodeBase64( line[0]); - writeFile(pathOut, encode); - }); -}); - -module.exports = encodingBase64; \ No newline at end of file diff --git a/Crypto/DES/decryptDES.js b/Crypto/DES/decryptDES.js deleted file mode 100644 index c32c545..0000000 --- a/Crypto/DES/decryptDES.js +++ /dev/null @@ -1,8 +0,0 @@ -const CryptoJS = require("crypto-js"); - -const decryptDES = ((decryptMessage, secretKey) => { - let decrypted = CryptoJS.DES.decrypt(decryptMessage, secretKey).toString(CryptoJS.enc.Utf8); - return decrypted; -}); - -module.exports = decryptDES; \ No newline at end of file diff --git a/Crypto/DES/decryptingDES.js b/Crypto/DES/decryptingDES.js deleted file mode 100644 index 72dbd68..0000000 --- a/Crypto/DES/decryptingDES.js +++ /dev/null @@ -1,15 +0,0 @@ -const fs = require('fs'); -const { parse } = require("csv-parse"); -const decryptDES = require('./decryptDES'); -const writeFile = require('../../Files/writeFile'); - -const decryptingDES = (({pathIn, pathOut, secretKey}) => { - fs.createReadStream(pathIn) - .pipe(parse({ delimiter: ",", from_line: 1 })) - .on("data", (line) => { - const dencrypt = decryptDES( line[0], secretKey); - writeFile(pathOut, dencrypt); - }); -}); - -module.exports = decryptingDES; \ No newline at end of file diff --git a/Crypto/DES/encryptDES.js b/Crypto/DES/encryptDES.js deleted file mode 100644 index 3908182..0000000 --- a/Crypto/DES/encryptDES.js +++ /dev/null @@ -1,8 +0,0 @@ -const CryptoJS = require("crypto-js"); - -const encryptAES = ((encryptMessage, secretKey) => { - let encrypted = CryptoJS.AES.encrypt(encryptMessage, secretKey); - return encrypted; -}); - -module.exports = encryptAES; \ No newline at end of file diff --git a/Crypto/DES/encryptingDES.js b/Crypto/DES/encryptingDES.js deleted file mode 100644 index 7036198..0000000 --- a/Crypto/DES/encryptingDES.js +++ /dev/null @@ -1,15 +0,0 @@ -const fs = require('fs'); -const { parse } = require("csv-parse"); -const encryptDES = require('./encryptDES'); -const writeFile = require('../../Files/writeFile'); - -const encryptingDES = (({pathIn, pathOut, secretKey}) => { - fs.createReadStream(pathIn) - .pipe(parse({ delimiter: ",", from_line: 1 })) - .on("data", (line) => { - const encrypt = encryptDES( line[0], secretKey); - writeFile(pathOut, encrypt); - }); -}); - -module.exports = encryptingDES; \ No newline at end of file diff --git a/Crypto/HEX/encodeHEX.js b/Crypto/HEX/encodeHEX.js deleted file mode 100644 index 28c6107..0000000 --- a/Crypto/HEX/encodeHEX.js +++ /dev/null @@ -1,8 +0,0 @@ -const CryptoJS = require("crypto-js"); - -const encodeHEX = ((encodeMessage) => { - let encode = encodeMessage.toString(CryptoJS.enc.Hex); - return encode; -}); - -module.exports = encodeHEX; \ No newline at end of file diff --git a/Crypto/HEX/encodingHEX.js b/Crypto/HEX/encodingHEX.js deleted file mode 100644 index d4d1c17..0000000 --- a/Crypto/HEX/encodingHEX.js +++ /dev/null @@ -1,15 +0,0 @@ -const fs = require('fs'); -const { parse } = require("csv-parse"); -const encodeHEX = require('./encodeHEX'); -const writeFile = require('../../Files/writeFile'); - -const encodingHEX = (({pathIn, pathOut}) => { - fs.createReadStream(pathIn) - .pipe(parse({ delimiter: ",", from_line: 1 })) - .on("data", (line) => { - const encode = encodeHEX( line[0]); - writeFile(pathOut, encode); - }); -}); - -module.exports = encodingHEX; \ No newline at end of file diff --git a/Crypto/HMAC/encryptHMAC.js b/Crypto/HMAC/encryptHMAC.js deleted file mode 100644 index 5288d90..0000000 --- a/Crypto/HMAC/encryptHMAC.js +++ /dev/null @@ -1,23 +0,0 @@ -const CryptoJS = require("crypto-js"); - -const encryptHMACMD5 = ((encryptMessage, secretKey) => { - let encrypted = CryptoJS.HmacMD5(encryptMessage, secretKey); - return encrypted; -}); - -const encryptHMACSHA1 = ((encryptMessage, secretKey) => { - let encrypted = CryptoJS.HmacSHA1(encryptMessage, secretKey); - return encrypted; -}); - -const encryptHMACSHA256 = ((encryptMessage, secretKey) => { - let encrypted = CryptoJS.HmacSHA256(encryptMessage, secretKey); - return encrypted; -}); - -const encryptHMACSHA512 = ((encryptMessage, secretKey) => { - let encrypted = CryptoJS.HmacSHA512(encryptMessage, secretKey); - return encrypted; -}); - -module.exports = { encryptHMACMD5, encryptHMACSHA1, encryptHMACSHA256, encryptHMACSHA512 }; \ No newline at end of file diff --git a/Crypto/HMAC/encryptingHMAC.js b/Crypto/HMAC/encryptingHMAC.js deleted file mode 100644 index 9c75c35..0000000 --- a/Crypto/HMAC/encryptingHMAC.js +++ /dev/null @@ -1,43 +0,0 @@ -const fs = require('fs'); -const { parse } = require("csv-parse"); -const { encryptHMACMD5, encryptHMACSHA1, encryptHMACSHA256, encryptHMACSHA512 } = require('./encryptHMAC'); -const writeFile = require('../../Files/writeFile'); - -const encryptingHMACMD5 = (({pathIn, pathOut, secretKey}) => { - fs.createReadStream(pathIn) - .pipe(parse({ delimiter: ",", from_line: 1 })) - .on("data", (line) => { - const encrypt = encryptHMACMD5( line[0]); - writeFile(pathOut, encrypt); - }); -}); - -const encryptingHMACSHA1 = (({pathIn, pathOut, secretKey}) => { - fs.createReadStream(pathIn) - .pipe(parse({ delimiter: ",", from_line: 1 })) - .on("data", (line) => { - const encrypt = encryptHMACSHA1( line[0]); - writeFile(pathOut, encrypt); - }); -}); - -const encryptingHMACSHA256 = (({pathIn, pathOut, secretKey}) => { - fs.createReadStream(pathIn) - .pipe(parse({ delimiter: ",", from_line: 1 })) - .on("data", (line) => { - const encrypt = encryptHMACSHA256( line[0]); - writeFile(pathOut, encrypt); - }); -}); - -const encryptingHMACSHA512 = (({pathIn, pathOut, secretKey}) => { - fs.createReadStream(pathIn) - .pipe(parse({ delimiter: ",", from_line: 1 })) - .on("data", (line) => { - const encrypt = encryptHMACSHA512( line[0]); - writeFile(pathOut, encrypt); - }); -}); - - -module.exports = { encryptingHMACMD5, encryptingHMACSHA1, encryptingHMACSHA256, encryptingHMACSHA512 }; \ No newline at end of file diff --git a/Crypto/MD5/encryptMD5.js b/Crypto/MD5/encryptMD5.js deleted file mode 100644 index ddb5626..0000000 --- a/Crypto/MD5/encryptMD5.js +++ /dev/null @@ -1,8 +0,0 @@ -const CryptoJS = require("crypto-js"); - -const encryptMD5 = ((encryptMessage) => { - let encrypted = CryptoJS.MD5(encryptMessage); - return encrypted; -}); - -module.exports = encryptMD5; \ No newline at end of file diff --git a/Crypto/MD5/encryptingMD5.js b/Crypto/MD5/encryptingMD5.js deleted file mode 100644 index 0b2dbc8..0000000 --- a/Crypto/MD5/encryptingMD5.js +++ /dev/null @@ -1,15 +0,0 @@ -const fs = require('fs'); -const { parse } = require("csv-parse"); -const encryptMD5 = require('./encryptMD5'); -const writeFile = require('../../Files/writeFile'); - -const encryptingMD5 = (({pathIn, pathOut}) => { - fs.createReadStream(pathIn) - .pipe(parse({ delimiter: ",", from_line: 1 })) - .on("data", (line) => { - const encrypt = encryptMD5( line[0]); - writeFile(pathOut, encrypt); - }); -}); - -module.exports = encryptingMD5; \ No newline at end of file diff --git a/Crypto/RIPEMD160/encryptRIPEMD160.js b/Crypto/RIPEMD160/encryptRIPEMD160.js deleted file mode 100644 index b5e822e..0000000 --- a/Crypto/RIPEMD160/encryptRIPEMD160.js +++ /dev/null @@ -1,8 +0,0 @@ -const CryptoJS = require("crypto-js"); - -const encryptRIPEMD160 = ((encryptMessage) => { - let encrypted = CryptoJS.RIPEMD160(encryptMessage); - return encrypted; -}); - -module.exports = encryptRIPEMD160; \ No newline at end of file diff --git a/Crypto/RIPEMD160/encryptingRIPEMD160.js b/Crypto/RIPEMD160/encryptingRIPEMD160.js deleted file mode 100644 index d0e9270..0000000 --- a/Crypto/RIPEMD160/encryptingRIPEMD160.js +++ /dev/null @@ -1,15 +0,0 @@ -const fs = require('fs'); -const { parse } = require("csv-parse"); -const encryptRIPEMD160 = require('./encryptRIPEMD160'); -const writeFile = require('../../Files/writeFile'); - -const encryptingRIPEMD160 = (({pathIn, pathOut}) => { - fs.createReadStream(pathIn) - .pipe(parse({ delimiter: ",", from_line: 1 })) - .on("data", (line) => { - const encrypt = encryptRIPEMD160( line[0]); - writeFile(pathOut, encrypt); - }); -}); - -module.exports = encryptingRIPEMD160; \ No newline at end of file diff --git a/Crypto/Rabbit/decryptRabbit.js b/Crypto/Rabbit/decryptRabbit.js deleted file mode 100644 index c767539..0000000 --- a/Crypto/Rabbit/decryptRabbit.js +++ /dev/null @@ -1,8 +0,0 @@ -const CryptoJS = require("crypto-js"); - -const decryptRabbit = ((decryptMessage, secretKey) => { - let decrypted = CryptoJS.Rabbit.decrypt(decryptMessage, secretKey).toString(CryptoJS.enc.Utf8); - return decrypted; -}); - -module.exports = decryptRabbit; \ No newline at end of file diff --git a/Crypto/Rabbit/decryptingRabbit.js b/Crypto/Rabbit/decryptingRabbit.js deleted file mode 100644 index ef94a15..0000000 --- a/Crypto/Rabbit/decryptingRabbit.js +++ /dev/null @@ -1,15 +0,0 @@ -const fs = require('fs'); -const { parse } = require("csv-parse"); -const decryptRabbit = require('./decryptRabbit'); -const writeFile = require('../../Files/writeFile'); - -const decryptingRabbit = (({pathIn, pathOut, secretKey}) => { - fs.createReadStream(pathIn) - .pipe(parse({ delimiter: ",", from_line: 1 })) - .on("data", (line) => { - const dencrypt = decryptRabbit( line[0], secretKey); - writeFile(pathOut, dencrypt); - }); -}); - -module.exports = decryptingRabbit; \ No newline at end of file diff --git a/Crypto/Rabbit/encryptRabbit.js b/Crypto/Rabbit/encryptRabbit.js deleted file mode 100644 index 91d021e..0000000 --- a/Crypto/Rabbit/encryptRabbit.js +++ /dev/null @@ -1,8 +0,0 @@ -const CryptoJS = require("crypto-js"); - -const encryptRabbit = ((encryptMessage, secretKey) => { - let encrypted = CryptoJS.Rabbit.encrypt(encryptMessage, secretKey); - return encrypted; -}); - -module.exports = encryptRabbit; \ No newline at end of file diff --git a/Crypto/Rabbit/encryptingRabbit.js b/Crypto/Rabbit/encryptingRabbit.js deleted file mode 100644 index a572c55..0000000 --- a/Crypto/Rabbit/encryptingRabbit.js +++ /dev/null @@ -1,15 +0,0 @@ -const fs = require('fs'); -const { parse } = require("csv-parse"); -const encryptRabbit = require('./encryptRabbit'); -const writeFile = require('../../Files/writeFile'); - -const encryptingRabbit = (({pathIn, pathOut, secretKey}) => { - fs.createReadStream(pathIn) - .pipe(parse({ delimiter: ",", from_line: 1 })) - .on("data", (line) => { - const encrypt = encryptRabbit( line[0], secretKey); - writeFile(pathOut, encrypt); - }); -}); - -module.exports = encryptingRabbit; \ No newline at end of file diff --git a/Crypto/SHA1/encryptSHA1.js b/Crypto/SHA1/encryptSHA1.js deleted file mode 100644 index 5fe2fae..0000000 --- a/Crypto/SHA1/encryptSHA1.js +++ /dev/null @@ -1,8 +0,0 @@ -const CryptoJS = require("crypto-js"); - -const encryptSHA1 = ((encryptMessage) => { - let encrypted = CryptoJS.SHA1(encryptMessage); - return encrypted; -}); - -module.exports = encryptSHA1; \ No newline at end of file diff --git a/Crypto/SHA1/encryptingSHA1.js b/Crypto/SHA1/encryptingSHA1.js deleted file mode 100644 index 5c27508..0000000 --- a/Crypto/SHA1/encryptingSHA1.js +++ /dev/null @@ -1,15 +0,0 @@ -const fs = require('fs'); -const { parse } = require("csv-parse"); -const encryptSHA1 = require('./encryptSHA1'); -const writeFile = require('../../Files/writeFile'); - -const encryptingSHA1 = (({pathIn, pathOut}) => { - fs.createReadStream(pathIn) - .pipe(parse({ delimiter: ",", from_line: 1 })) - .on("data", (line) => { - const encrypt = encryptSHA1( line[0]); - writeFile(pathOut, encrypt); - }); -}); - -module.exports = encryptingSHA1; \ No newline at end of file diff --git a/Crypto/SHA256/encryptSHA256.js b/Crypto/SHA256/encryptSHA256.js deleted file mode 100644 index 0dd81b9..0000000 --- a/Crypto/SHA256/encryptSHA256.js +++ /dev/null @@ -1,8 +0,0 @@ -const CryptoJS = require("crypto-js"); - -const encryptSHA256 = ((encryptMessage) => { - let encrypted = CryptoJS.SHA256(encryptMessage); - return encrypted; -}); - -module.exports = encryptSHA256; \ No newline at end of file diff --git a/Crypto/SHA256/encryptingSHA256.js b/Crypto/SHA256/encryptingSHA256.js deleted file mode 100644 index a0b2b7d..0000000 --- a/Crypto/SHA256/encryptingSHA256.js +++ /dev/null @@ -1,15 +0,0 @@ -const fs = require('fs'); -const { parse } = require("csv-parse"); -const encryptSHA256 = require('./encryptSHA256'); -const writeFile = require('../../Files/writeFile'); - -const encryptingSHA256 = (({pathIn, pathOut}) => { - fs.createReadStream(pathIn) - .pipe(parse({ delimiter: ",", from_line: 1 })) - .on("data", (line) => { - const encrypt = encryptSHA256( line[0]); - writeFile(pathOut, encrypt); - }); -}); - -module.exports = encryptingSHA256; \ No newline at end of file diff --git a/Crypto/SHA3/encryptSHA3.js b/Crypto/SHA3/encryptSHA3.js deleted file mode 100644 index d9828d6..0000000 --- a/Crypto/SHA3/encryptSHA3.js +++ /dev/null @@ -1,8 +0,0 @@ -const CryptoJS = require("crypto-js"); - -const encryptSHA3 = ((encryptMessage, outputLengthNum) => { - let encrypted = CryptoJS.SHA3(encryptMessage, { outputLength: outputLengthNum }); - return encrypted; -}); - -module.exports = encryptSHA3; \ No newline at end of file diff --git a/Crypto/SHA3/encryptingSHA3.js b/Crypto/SHA3/encryptingSHA3.js deleted file mode 100644 index 17810f9..0000000 --- a/Crypto/SHA3/encryptingSHA3.js +++ /dev/null @@ -1,15 +0,0 @@ -const fs = require('fs'); -const { parse } = require("csv-parse"); -const encryptSHA3 = require('./encryptSHA3'); -const writeFile = require('../../Files/writeFile'); - -const encryptingSHA3 = (({pathIn, pathOut, outputLength}) => { - fs.createReadStream(pathIn) - .pipe(parse({ delimiter: ",", from_line: 1 })) - .on("data", (line) => { - const encrypt = encryptSHA3( line[0], outputLength); - writeFile(pathOut, encrypt); - }); -}); - -module.exports = encryptingSHA3; \ No newline at end of file diff --git a/Crypto/SHA512/encryptSHA512.js b/Crypto/SHA512/encryptSHA512.js deleted file mode 100644 index d7612c8..0000000 --- a/Crypto/SHA512/encryptSHA512.js +++ /dev/null @@ -1,8 +0,0 @@ -const CryptoJS = require("crypto-js"); - -const encryptSHA512 = ((encryptMessage) => { - let encrypted = CryptoJS.SHA512(encryptMessage); - return encrypted; -}); - -module.exports = encryptSHA512; \ No newline at end of file diff --git a/Crypto/SHA512/encryptingSHA512.js b/Crypto/SHA512/encryptingSHA512.js deleted file mode 100644 index 77b417c..0000000 --- a/Crypto/SHA512/encryptingSHA512.js +++ /dev/null @@ -1,15 +0,0 @@ -const fs = require('fs'); -const { parse } = require("csv-parse"); -const encryptSHA512 = require('./encryptSHA512'); -const writeFile = require('../../Files/writeFile'); - -const encryptingSHA512 = (({pathIn, pathOut}) => { - fs.createReadStream(pathIn) - .pipe(parse({ delimiter: ",", from_line: 1 })) - .on("data", (line) => { - const encrypt = encryptSHA512( line[0]); - writeFile(pathOut, encrypt); - }); -}); - -module.exports = encryptingSHA512; \ No newline at end of file diff --git a/Crypto/Salt/salt.js b/Crypto/Salt/salt.js deleted file mode 100644 index 57e2a45..0000000 --- a/Crypto/Salt/salt.js +++ /dev/null @@ -1,7 +0,0 @@ -const CryptoJS = require("crypto-js"); - -const salt = ((saltMessage) => { - return saltMessage.salt.toString(); -}); - -module.exports = salt; \ No newline at end of file diff --git a/Crypto/Salt/salting.js b/Crypto/Salt/salting.js deleted file mode 100644 index e6b8c9d..0000000 --- a/Crypto/Salt/salting.js +++ /dev/null @@ -1,15 +0,0 @@ -const fs = require('fs'); -const { parse } = require("csv-parse"); -const salt = require('./salt'); -const writeFile = require('../../Files/writeFile'); - -const salting = (({pathIn, pathOut}) => { - fs.createReadStream(pathIn) - .pipe(parse({ delimiter: ",", from_line: 1 })) - .on("data", (line) => { - const saltt = salt( line[0]); - writeFile(pathOut, saltt); - }); -}); - -module.exports = salting; \ No newline at end of file diff --git a/Crypto/TripleDES/decryptTripleDES.js b/Crypto/TripleDES/decryptTripleDES.js deleted file mode 100644 index 9bfb728..0000000 --- a/Crypto/TripleDES/decryptTripleDES.js +++ /dev/null @@ -1,8 +0,0 @@ -const CryptoJS = require("crypto-js"); - -const decryptTripleDES = ((decryptMessage, secretKey) => { - let decrypted = CryptoJS.TripleDES.decrypt(decryptMessage, secretKey).toString(CryptoJS.enc.Utf8); - return decrypted; -}); - -module.exports = decryptTripleDES; \ No newline at end of file diff --git a/Crypto/TripleDES/decryptingTripleDES.js b/Crypto/TripleDES/decryptingTripleDES.js deleted file mode 100644 index 0c26381..0000000 --- a/Crypto/TripleDES/decryptingTripleDES.js +++ /dev/null @@ -1,15 +0,0 @@ -const fs = require('fs'); -const { parse } = require("csv-parse"); -const decryptTripleDES = require('./decryptTripleDES'); -const writeFile = require('../../Files/writeFile'); - -const decryptingTripleDES = (({pathIn, pathOut, secretKey}) => { - fs.createReadStream(pathIn) - .pipe(parse({ delimiter: ",", from_line: 1 })) - .on("data", (line) => { - const dencrypt = decryptTripleDES( line[0], secretKey); - writeFile(pathOut, dencrypt); - }); -}); - -module.exports = decryptingTripleDES; \ No newline at end of file diff --git a/Crypto/TripleDES/encryptTripleDES.js b/Crypto/TripleDES/encryptTripleDES.js deleted file mode 100644 index 361fdc3..0000000 --- a/Crypto/TripleDES/encryptTripleDES.js +++ /dev/null @@ -1,8 +0,0 @@ -const CryptoJS = require("crypto-js"); - -const encryptTripleDES = ((encryptMessage, secretKey) => { - let encrypted = CryptoJS.TripleDES.encrypt(encryptMessage, secretKey); - return encrypted; -}); - -module.exports = encryptTripleDES; \ No newline at end of file diff --git a/Crypto/TripleDES/encryptingTripleDES.js b/Crypto/TripleDES/encryptingTripleDES.js deleted file mode 100644 index fd9a29e..0000000 --- a/Crypto/TripleDES/encryptingTripleDES.js +++ /dev/null @@ -1,15 +0,0 @@ -const fs = require('fs'); -const { parse } = require("csv-parse"); -const encryptTripleDES = require('./encryptTripleDES'); -const writeFile = require('../../Files/writeFile'); - -const encryptingTripleDES = (({pathIn, pathOut, secretKey}) => { - fs.createReadStream(pathIn) - .pipe(parse({ delimiter: ",", from_line: 1 })) - .on("data", (line) => { - const encrypt = encryptTripleDES( line[0], secretKey); - writeFile(pathOut, encrypt); - }); -}); - -module.exports = encryptingTripleDES; \ No newline at end of file diff --git a/Files/readFile.js b/Files/readFile.js deleted file mode 100644 index aeed299..0000000 --- a/Files/readFile.js +++ /dev/null @@ -1,8 +0,0 @@ -const fs = require('fs'); - -const readFile = (({pathOut}) => { - data = fs.readFileSync(pathOut); - return data.toString().split('\n'); -}); - -module.exports = readFile; \ No newline at end of file diff --git a/Files/writeFile.js b/Files/writeFile.js deleted file mode 100644 index 331a0c7..0000000 --- a/Files/writeFile.js +++ /dev/null @@ -1,11 +0,0 @@ -const fs = require('fs'); - -const writeFile = ((pathOut, cpfCrypto) => { - try { - fs.appendFileSync(pathOut,cpfCrypto + '\n'); - } catch (err) { - console.error(err); - } -}); - -module.exports = writeFile; \ No newline at end of file diff --git a/GenerateWordlistCryptoJS.postman_collection.json b/GenerateWordlistCryptoJS.postman_collection.json index a960356..9ae11c2 100644 --- a/GenerateWordlistCryptoJS.postman_collection.json +++ b/GenerateWordlistCryptoJS.postman_collection.json @@ -1,9 +1,8 @@ { "info": { - "_postman_id": "f6845995-7bbe-4d03-96ce-e05a8474dd0e", + "_postman_id": "8217f62c-47ef-403a-8abd-02615dac43d5", "name": "GenerateWordlistCryptoJS", - "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json", - "_exporter_id": "5662943" + "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json" }, "item": [ { @@ -24,15 +23,10 @@ } }, "url": { - "raw": "http://127.0.0.1:3000/AES/encrypting", - "protocol": "http", + "raw": "{{ENDPOINT}}/AES/encrypting", "host": [ - "127", - "0", - "0", - "1" + "{{ENDPOINT}}" ], - "port": "3000", "path": [ "AES", "encrypting" @@ -56,15 +50,10 @@ } }, "url": { - "raw": "http://127.0.0.1:3000/AES/decrypting", - "protocol": "http", + "raw": "{{ENDPOINT}}/AES/decrypting", "host": [ - "127", - "0", - "0", - "1" + "{{ENDPOINT}}" ], - "port": "3000", "path": [ "AES", "decrypting" @@ -93,15 +82,10 @@ } }, "url": { - "raw": "http://127.0.0.1:3000/DES/encrypting", - "protocol": "http", + "raw": "{{ENDPOINT}}/DES/encrypting", "host": [ - "127", - "0", - "0", - "1" + "{{ENDPOINT}}" ], - "port": "3000", "path": [ "DES", "encrypting" @@ -125,15 +109,10 @@ } }, "url": { - "raw": "http://127.0.0.1:3000/DES/decrypting", - "protocol": "http", + "raw": "{{ENDPOINT}}/DES/decrypting", "host": [ - "127", - "0", - "0", - "1" + "{{ENDPOINT}}" ], - "port": "3000", "path": [ "DES", "decrypting" @@ -162,15 +141,74 @@ } }, "url": { - "raw": "http://127.0.0.1:3000/MD5/encrypting", - "protocol": "http", + "raw": "{{ENDPOINT}}/MD5/encrypting", "host": [ - "127", - "0", - "0", - "1" + "{{ENDPOINT}}" + ], + "path": [ + "MD5", + "encrypting" + ] + } + }, + "response": [] + } + ] + }, + { + "name": "Base64", + "item": [ + { + "name": "Wordlist Base64 encrypt", + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"pathIn\": \"./Wordlists/wordlistCPFUsuarios.csv\",\n \"pathOut\": \"./Wordlists/wordlistCryptCPFUsuarios.csv\"\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{ENDPOINT}}/MD5/encrypting", + "host": [ + "{{ENDPOINT}}" + ], + "path": [ + "MD5", + "encrypting" + ] + } + }, + "response": [] + } + ] + }, + { + "name": "Hex", + "item": [ + { + "name": "Wordlist Hex encrypt", + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"pathIn\": \"./Wordlists/wordlistCPFUsuarios.csv\",\n \"pathOut\": \"./Wordlists/wordlistCryptCPFUsuarios.csv\"\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{ENDPOINT}}/MD5/encrypting", + "host": [ + "{{ENDPOINT}}" ], - "port": "3000", "path": [ "MD5", "encrypting" @@ -199,15 +237,10 @@ } }, "url": { - "raw": "http://127.0.0.1:3000/SHA1/encrypting", - "protocol": "http", + "raw": "{{ENDPOINT}}/SHA1/encrypting", "host": [ - "127", - "0", - "0", - "1" + "{{ENDPOINT}}" ], - "port": "3000", "path": [ "SHA1", "encrypting" @@ -236,15 +269,10 @@ } }, "url": { - "raw": "http://127.0.0.1:3000/SHA256/encrypting", - "protocol": "http", + "raw": "{{ENDPOINT}}/SHA256/encrypting", "host": [ - "127", - "0", - "0", - "1" + "{{ENDPOINT}}" ], - "port": "3000", "path": [ "SHA256", "encrypting" @@ -268,15 +296,10 @@ } }, "url": { - "raw": "http://127.0.0.1:3000/SHA512/encrypting", - "protocol": "http", + "raw": "{{ENDPOINT}}/SHA512/encrypting", "host": [ - "127", - "0", - "0", - "1" + "{{ENDPOINT}}" ], - "port": "3000", "path": [ "SHA512", "encrypting" @@ -305,15 +328,10 @@ } }, "url": { - "raw": "http://127.0.0.1:3000/SHA3/encrypting", - "protocol": "http", + "raw": "{{ENDPOINT}}/SHA3/encrypting", "host": [ - "127", - "0", - "0", - "1" + "{{ENDPOINT}}" ], - "port": "3000", "path": [ "SHA3", "encrypting" @@ -342,15 +360,10 @@ } }, "url": { - "raw": "http://127.0.0.1:3000/TripleDES/encrypting", - "protocol": "http", + "raw": "{{ENDPOINT}}/TripleDES/encrypting", "host": [ - "127", - "0", - "0", - "1" + "{{ENDPOINT}}" ], - "port": "3000", "path": [ "TripleDES", "encrypting" @@ -374,15 +387,10 @@ } }, "url": { - "raw": "http://127.0.0.1:3000/TripleDES/decrypting", - "protocol": "http", + "raw": "{{ENDPOINT}}/TripleDES/decrypting", "host": [ - "127", - "0", - "0", - "1" + "{{ENDPOINT}}" ], - "port": "3000", "path": [ "TripleDES", "decrypting" @@ -411,15 +419,10 @@ } }, "url": { - "raw": "http://127.0.0.1:3000/Rabbit/encrypting", - "protocol": "http", + "raw": "{{ENDPOINT}}/Rabbit/encrypting", "host": [ - "127", - "0", - "0", - "1" + "{{ENDPOINT}}" ], - "port": "3000", "path": [ "Rabbit", "encrypting" @@ -443,15 +446,10 @@ } }, "url": { - "raw": "http://127.0.0.1:3000/Rabbit/decrypting", - "protocol": "http", + "raw": "{{ENDPOINT}}/Rabbit/decrypting", "host": [ - "127", - "0", - "0", - "1" + "{{ENDPOINT}}" ], - "port": "3000", "path": [ "Rabbit", "decrypting" @@ -480,15 +478,10 @@ } }, "url": { - "raw": "http://127.0.0.1:3000/Base64/encoding", - "protocol": "http", + "raw": "{{ENDPOINT}}/Base64/encoding", "host": [ - "127", - "0", - "0", - "1" + "{{ENDPOINT}}" ], - "port": "3000", "path": [ "Base64", "encoding" @@ -512,15 +505,10 @@ } }, "url": { - "raw": "http://127.0.0.1:3000/HEX/encoding", - "protocol": "http", + "raw": "{{ENDPOINT}}/HEX/encoding", "host": [ - "127", - "0", - "0", - "1" + "{{ENDPOINT}}" ], - "port": "3000", "path": [ "HEX", "encoding" @@ -549,15 +537,10 @@ } }, "url": { - "raw": "http://127.0.0.1:3000/Salt/salting", - "protocol": "http", + "raw": "{{ENDPOINT}}/Salt/salting", "host": [ - "127", - "0", - "0", - "1" + "{{ENDPOINT}}" ], - "port": "3000", "path": [ "Salt", "salting" @@ -586,15 +569,10 @@ } }, "url": { - "raw": "http://127.0.0.1:3000/HMAC/MD5/encrypting", - "protocol": "http", + "raw": "{{ENDPOINT}}/HMAC/MD5/encrypting", "host": [ - "127", - "0", - "0", - "1" + "{{ENDPOINT}}" ], - "port": "3000", "path": [ "HMAC", "MD5", @@ -723,15 +701,10 @@ } }, "url": { - "raw": "http://127.0.0.1:3000/getAllFile", - "protocol": "http", + "raw": "{{ENDPOINT}}/getAllFile", "host": [ - "127", - "0", - "0", - "1" + "{{ENDPOINT}}" ], - "port": "3000", "path": [ "getAllFile" ] @@ -739,5 +712,32 @@ }, "response": [] } + ], + "event": [ + { + "listen": "prerequest", + "script": { + "type": "text/javascript", + "exec": [ + "" + ] + } + }, + { + "listen": "test", + "script": { + "type": "text/javascript", + "exec": [ + "" + ] + } + } + ], + "variable": [ + { + "key": "ENDPOINT", + "value": "http://localhost:3000", + "type": "default" + } ] } \ No newline at end of file diff --git a/app.js b/app.js deleted file mode 100644 index 523d143..0000000 --- a/app.js +++ /dev/null @@ -1,172 +0,0 @@ -const { http, express, encryptingAES, decryptingAES, encryptingDES, decryptingDES, encryptingTripleDES, decryptingTripleDES, encryptingRabbit, decryptingRabbit, encryptingMD5, encryptingSHA1, encryptingSHA256, encryptingSHA512, encryptingSHA3, encryptingRIPEMD160, encodingBase64, salting, encodingHEX, encryptingHMACMD5, encryptingHMACSHA1, encryptingHMACSHA256, encryptingHMACSHA512, readFile } = require('./requires'); - -const server = express(); -server.use(express.json()); - -const hostname = '127.0.0.1'; -const port = 3000; - -server.get('/', () => { - console.log(`Server running at http://${hostname}:${port}/`); -}); - -// Get All information File - -server.get('/getAllFile', (req, res) => { - let { pathOut } = req.body; - const wordlistEncrypted = readFile({ pathOut }); - return res.json({ wordlistEncrypted }) -}); - -// AES - -server.post('/AES/encrypting', (req, res) => { - const { pathIn, pathOut, secretKey } = req.body; - encryptingAES({ pathIn, pathOut, secretKey }); - return res.json({ Message: 'Deu certo! Use o get para buscar as informações ou abra o arquivo.', PathFile: pathOut }); -}); - -server.post('/AES/decrypting', (req, res) => { - const { pathIn, pathOut, secretKey } = req.body; - decryptingAES({ pathIn, pathOut, secretKey }); - return res.json({ Message: 'Deu certo! Use o get para buscar as informações ou abra o arquivo.', PathFile: pathOut }); -}); - -// DES - -server.post('/DES/encrypting', (req, res) => { - const { pathIn, pathOut, secretKey } = req.body; - encryptingDES({ pathIn, pathOut, secretKey }); - return res.json({ Message: 'Deu certo! Use o get para buscar as informações ou abra o arquivo.', PathFile: pathOut }); -}); - -server.post('/DES/decrypting', (req, res) => { - const { pathIn, pathOut, secretKey } = req.body; - decryptingDES({ pathIn, pathOut, secretKey }); - return res.json({ Message: 'Deu certo! Use o get para buscar as informações ou abra o arquivo.', PathFile: pathOut }); -}); - - -// Triple DES - -server.post('/TripleDES/encrypting', (req, res) => { - const { pathIn, pathOut, secretKey } = req.body; - encryptingTripleDES({ pathIn, pathOut, secretKey }); - return res.json({ Message: 'Deu certo! Use o get para buscar as informações ou abra o arquivo.', PathFile: pathOut }); -}); - -server.post('/TripleDES/decrypting', (req, res) => { - const { pathIn, pathOut, secretKey } = req.body; - decryptingTripleDES({ pathIn, pathOut, secretKey }); - return res.json({ Message: 'Deu certo! Use o get para buscar as informações ou abra o arquivo.', PathFile: pathOut }); -}); - -// Rabbit - -server.post('/Rabbit/encrypting', (req, res) => { - const { pathIn, pathOut, secretKey } = req.body; - encryptingRabbit({ pathIn, pathOut, secretKey }); - return res.json({ Message: 'Deu certo! Use o get para buscar as informações ou abra o arquivo.', PathFile: pathOut }); -}); - -server.post('/Rabbit/decrypting', (req, res) => { - const { pathIn, pathOut, secretKey } = req.body; - decryptingRabbit({ pathIn, pathOut, secretKey }); - return res.json({ Message: 'Deu certo! Use o get para buscar as informações ou abra o arquivo.', PathFile: pathOut }); -}); - -// MD5 - -server.post('/MD5/encrypting', (req, res) => { - const { pathIn, pathOut } = req.body; - encryptingMD5({ pathIn, pathOut }); - return res.json({ Message: 'Deu certo! Use o get para buscar as informações ou abra o arquivo.', PathFile: pathOut }); -}); - -// SHA1 - -server.post('/SHA1/encrypting', (req, res) => { - const { pathIn, pathOut } = req.body; - encryptingSHA1({ pathIn, pathOut }); - return res.json({ Message: 'Deu certo! Use o get para buscar as informações ou abra o arquivo.', PathFile: pathOut }); -}); - -// SHA2 - -server.post('/SHA256/encrypting', (req, res) => { - const { pathIn, pathOut } = req.body; - encryptingSHA256({ pathIn, pathOut }); - return res.json({ Message: 'Deu certo! Use o get para buscar as informações ou abra o arquivo.', PathFile: pathOut }); -}); - -server.post('/SHA512/encrypting', (req, res) => { - const { pathIn, pathOut } = req.body; - encryptingSHA512({ pathIn, pathOut }); - return res.json({ Message: 'Deu certo! Use o get para buscar as informações ou abra o arquivo.', PathFile: pathOut }); -}); - -// SHA3 - -server.post('/SHA3/encrypting', (req, res) => { - const { pathIn, pathOut, outputLength } = req.body; - encryptingSHA3({ pathIn, pathOut, outputLength }); - return res.json({ Message: 'Deu certo! Use o get para buscar as informações ou abra o arquivo.', PathFile: pathOut }); -}); - -// RIPEMD160 - -server.post('/RIPEMD160/encrypting', (req, res) => { - const { pathIn, pathOut } = req.body; - encryptingRIPEMD160({ pathIn, pathOut }); - return res.json({ Message: 'Deu certo! Use o get para buscar as informações ou abra o arquivo.', PathFile: pathOut }); -}); - -// ENCODING - -server.post('/Base64/encoding', (req, res) => { - const { pathIn, pathOut } = req.body; - encodingBase64({ pathIn, pathOut }); - return res.json({ Message: 'Deu certo! Use o get para buscar as informações ou abra o arquivo.', PathFile: pathOut }); -}); - -server.post('/HEX/encrypting', (req, res) => { - const { pathIn, pathOut } = req.body; - encodingHEX({ pathIn, pathOut }); - return res.json({ Message: 'Deu certo! Use o get para buscar as informações ou abra o arquivo.', PathFile: pathOut }); -}); - -// Salt - -server.post('/Salt/salting', (req, res) => { - const { pathIn, pathOut } = req.body; - salting({ pathIn, pathOut }); - return res.json({ Message: 'Deu certo! Use o get para buscar as informações ou abra o arquivo.', PathFile: pathOut }); -}); - -// HMAC - -server.post('/HMAC/MD5/encrypting', (req, res) => { - const { pathIn, pathOut, secretKey } = req.body; - encryptingHMACMD5({ pathIn, pathOut, secretKey }); - return res.json({ Message: 'Deu certo! Use o get para buscar as informações ou abra o arquivo.', PathFile: pathOut }); -}); - -server.post('/HMAC/SHA1/encrypting', (req, res) => { - const { pathIn, pathOut, secretKey } = req.body; - encryptingHMACSHA1({ pathIn, pathOut, secretKey }); - return res.json({ Message: 'Deu certo! Use o get para buscar as informações ou abra o arquivo.', PathFile: pathOut }); -}); - -server.post('/HMAC/SHA256/encrypting', (req, res) => { - const { pathIn, pathOut, secretKey } = req.body; - encryptingHMACSHA256({ pathIn, pathOut, secretKey }); - return res.json({ Message: 'Deu certo! Use o get para buscar as informações ou abra o arquivo.', PathFile: pathOut }); -}); - -server.post('/HMAC/SHA512/encrypting', (req, res) => { - const { pathIn, pathOut, secretKey } = req.body; - encryptingHMACSHA512({ pathIn, pathOut, secretKey }); - return res.json({ Message: 'Deu certo! Use o get para buscar as informações ou abra o arquivo.', PathFile: pathOut }); -}); - -server.listen(port); diff --git a/package-lock.json b/package-lock.json index da78b89..f54566e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,19 +9,21 @@ "version": "1.0.0", "license": "ISC", "dependencies": { - "@types/crypto-js": "^4.1.1", "crypto-js": "^4.1.1", "csv": "^6.2.12", + "dotenv": "^16.0.3", "express": "^4.18.2" }, "devDependencies": { + "@types/crypto-js": "^4.1.1", "@types/node": "^20.1.0" } }, "node_modules/@types/crypto-js": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/@types/crypto-js/-/crypto-js-4.1.1.tgz", - "integrity": "sha512-BG7fQKZ689HIoc5h+6D2Dgq1fABRa0RbBWKBd9SP/MVRVXROflpm5fhwyATX5duFmbStzyzyycPB8qUYKDH3NA==" + "integrity": "sha512-BG7fQKZ689HIoc5h+6D2Dgq1fABRa0RbBWKBd9SP/MVRVXROflpm5fhwyATX5duFmbStzyzyycPB8qUYKDH3NA==", + "dev": true }, "node_modules/@types/node": { "version": "20.1.0", @@ -180,6 +182,14 @@ "npm": "1.2.8000 || >= 1.4.16" } }, + "node_modules/dotenv": { + "version": "16.0.3", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.0.3.tgz", + "integrity": "sha512-7GO6HghkA5fYG9TYnNxi14/7K9f5occMlp3zXAuSxn7CKCxt9xbNWG7yF8hTCSUchlfWSe3uLmlPfigevRItzQ==", + "engines": { + "node": ">=12" + } + }, "node_modules/ee-first": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", diff --git a/package.json b/package.json index 96648f2..f78a27b 100644 --- a/package.json +++ b/package.json @@ -2,19 +2,20 @@ "name": "project-kapput-password", "version": "1.0.0", "description": "", - "main": "index.js", + "main": "./src/index.js", "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" + "start": "node ./src/index.js" }, "author": "", "license": "ISC", "dependencies": { - "@types/crypto-js": "^4.1.1", "crypto-js": "^4.1.1", "csv": "^6.2.12", + "dotenv": "^16.0.3", "express": "^4.18.2" }, "devDependencies": { + "@types/crypto-js": "^4.1.1", "@types/node": "^20.1.0" } } diff --git a/requires.js b/requires.js deleted file mode 100644 index 32ca5a4..0000000 --- a/requires.js +++ /dev/null @@ -1,24 +0,0 @@ -const http = require('http'); -const express = require('express'); -const encryptingAES = require('./Crypto/AES/encryptingAES'); -const decryptingAES = require('./Crypto/AES/decryptingAES'); -const encryptingDES = require('./Crypto/DES/encryptingDES'); -const decryptingDES = require('./Crypto/DES/decryptingDES'); -const encryptingTripleDES = require('./Crypto/TripleDES/encryptingTripleDES'); -const decryptingTripleDES = require('./Crypto/TripleDES/decryptingTripleDES'); -const encryptingRabbit = require('./Crypto/Rabbit/encryptingRabbit'); -const decryptingRabbit = require('./Crypto/Rabbit/decryptingRabbit'); -const encryptingMD5 = require('./Crypto/MD5/encryptingMD5'); -const encryptingSHA1 = require('./Crypto/SHA1/encryptingSHA1'); -const encryptingSHA256 = require('./Crypto/SHA256/encryptingSHA256'); -const encryptingSHA512 = require('./Crypto/SHA512/encryptingSHA512'); -const encryptingSHA3 = require('./Crypto/SHA3/encryptingSHA3'); -const encryptingRIPEMD160 = require('./Crypto/RIPEMD160/encryptingRIPEMD160'); -const encodingBase64 = require('./Crypto/Base64/encodingBase64'); -const salting = require('./Crypto/Salt/salting'); -const encodingHEX = require('./Crypto/HEX/encodingHEX'); -const { encryptingHMACMD5, encryptingHMACSHA1, encryptingHMACSHA256, encryptingHMACSHA512 } = require('./Crypto/HMAC/encryptingHMAC'); -const readFile = require('./Files/readFile'); - - -module.exports = { http, express, encryptingAES, decryptingAES, encryptingDES, decryptingDES, encryptingTripleDES, decryptingTripleDES, encryptingRabbit, decryptingRabbit, encryptingMD5, encryptingSHA1, encryptingSHA256, encryptingSHA512, encryptingSHA3, encryptingRIPEMD160, encodingBase64, salting, encodingHEX, encryptingHMACMD5, encryptingHMACSHA1, encryptingHMACSHA256, encryptingHMACSHA512, readFile }; \ No newline at end of file diff --git a/src/environment.js b/src/environment.js new file mode 100644 index 0000000..e0b009d --- /dev/null +++ b/src/environment.js @@ -0,0 +1,29 @@ +const ALLOWED_CRYPTO_TO_ENCRYPTING = [ + "AES", + "Base64", + "DES", + "HmacMD5", + "HmacSHA1", + "HmacSHA256", + "HmacSHA512", + "MD5", + "Rabbit", + "RIPEMD160", + "SHA1", + "SHA3", + "SHA256", + "SHA512", + "TripleDES", +]; + +const ALLOWED_CRYPTO_TO_DECRYPTING = ["AES", "DES", "Rabbit", "TripleDES"]; + +const HOSTNAME = process.env.APPLICATION_HOSTNAME || "127.0.0.1"; +const PORT = process.env.APPLICATION_PORT || 3000; + +module.exports = { + ALLOWED_CRYPTO_TO_ENCRYPTING, + ALLOWED_CRYPTO_TO_DECRYPTING, + HOSTNAME, + PORT, +}; diff --git a/src/handlers/cryptography-handler.js b/src/handlers/cryptography-handler.js new file mode 100644 index 0000000..a6112c5 --- /dev/null +++ b/src/handlers/cryptography-handler.js @@ -0,0 +1,96 @@ +const { + ALLOWED_CRYPTO_TO_DECRYPTING, + ALLOWED_CRYPTO_TO_ENCRYPTING, +} = require("../environment"); + +const { + FileService, + ReadStreamFromCSVService, + CipherService, +} = require("../services"); +const { HttpResponse } = require("../utils"); + +const encryptHandler = (req, res) => { + const { cryptography } = req.params; + + if (!ALLOWED_CRYPTO_TO_ENCRYPTING.includes(cryptography)) { + return res + .status(400) + .json( + HttpResponse.error( + `Criptografia inválida. Lista de Criptografias válidas: ${ALLOWED_CRYPTO_TO_ENCRYPTING.join( + ", " + )}`, + 400 + ) + ); + } + + const cipherService = new CipherService(cryptography); + const { pathIn, pathOut, secretKey } = req.body; + + const handleData = (chunk) => { + const encrypted = cipherService.encrypt({ + secretKey, + message: chunk[0], + }); + FileService.write({ path: pathOut, data: encrypted }); + }; + + ReadStreamFromCSVService.read(pathIn).on("data", handleData); + + return res.status(201).json( + HttpResponse.created( + "Deu certo! Use o get para buscar as informações ou abra o arquivo.", + { + outputPath: pathOut, + } + ) + ); +}; + +const decryptHandler = (req, res) => { + const { cryptography } = req.params; + + if (!ALLOWED_CRYPTO_TO_DECRYPTING.includes(cryptography)) { + return res + .status(400) + .json( + HttpResponse.error( + `Criptografia inválida. Lista de Criptografias válidas: ${ALLOWED_CRYPTO_TO_DECRYPTING.join( + ", " + )}`, + 400 + ) + ); + } + + const { pathIn, pathOut, secretKey } = req.body; + + const cipherService = new CipherService(cryptography); + + const handleData = (chunk) => { + const decrypted = cipherService.decrypt({ + secretKey, + message: chunk[0], + }); + + FileService.write({ path: pathOut, data: decrypted }); + }; + + ReadStreamFromCSVService.read(pathIn).on("data", handleData); + + return res.status(201).json( + HttpResponse.created( + "Deu certo! Use o get para buscar as informações ou abra o arquivo.", + { + outputPath: pathOut, + } + ) + ); +}; + +module.exports = { + encryptHandler, + decryptHandler, +}; diff --git a/src/handlers/custom-cryptography-handler.js b/src/handlers/custom-cryptography-handler.js new file mode 100644 index 0000000..c0d5334 --- /dev/null +++ b/src/handlers/custom-cryptography-handler.js @@ -0,0 +1,51 @@ +const { + FileService, + ReadStreamFromCSVService, + CipherCustomService, +} = require("../services"); +const { HttpResponse } = require("../utils"); + +const Base64EncryptHandler = (req, res) => { + const { pathIn, pathOut } = req.body; + + const handleData = (chunk) => { + const encrypted = CipherCustomService.toBase64(chunk[0]); + FileService.write({ path: pathOut, data: encrypted }); + }; + + ReadStreamFromCSVService.read(pathIn).on("data", handleData); + + return res.status(201).json( + HttpResponse.created( + "Deu certo! Use o get para buscar as informações ou abra o arquivo.", + { + outputPath: pathOut, + } + ) + ); +}; + +const SHA3EncryptHandler = (req, res) => { + const { pathIn, pathOut, outputLength } = req.body; + + const handleData = (chunk) => { + const encrypted = CipherCustomService.toSHA3(chunk[0], outputLength); + FileService.write({ path: pathOut, data: encrypted }); + }; + + ReadStreamFromCSVService.read(pathIn).on("data", handleData); + + return res.status(201).json( + HttpResponse.created( + "Deu certo! Use o get para buscar as informações ou abra o arquivo.", + { + outputPath: pathOut, + } + ) + ); +}; + +module.exports = { + Base64EncryptHandler, + SHA3EncryptHandler, +}; diff --git a/src/handlers/error-handler.js b/src/handlers/error-handler.js new file mode 100644 index 0000000..3057835 --- /dev/null +++ b/src/handlers/error-handler.js @@ -0,0 +1,11 @@ +const { HttpResponse } = require("../utils"); + +const errorHandler = (error, request, response, next) => { + if (!error) { + return next(); + } + + return response.status(500).json(HttpResponse.error(error.message, 500)); +}; + +module.exports = errorHandler; diff --git a/src/handlers/get-all-file-handler.js b/src/handlers/get-all-file-handler.js new file mode 100644 index 0000000..b5479ab --- /dev/null +++ b/src/handlers/get-all-file-handler.js @@ -0,0 +1,11 @@ +const { FileService } = require("../services"); +const { HttpResponse } = require("../utils"); + +const getAllFileHandler = (req, res) => { + let { pathOut } = req.body; + const wordlistEncrypted = FileService.read(pathOut); + + return res.json(HttpResponse.ok("Deu certo!", { wordlistEncrypted })); +}; + +module.exports = getAllFileHandler; diff --git a/src/handlers/index.js b/src/handlers/index.js new file mode 100644 index 0000000..71a6dbf --- /dev/null +++ b/src/handlers/index.js @@ -0,0 +1,11 @@ +const getAllFileHandler = require("./get-all-file-handler"); +const customCryptographyHandlers = require("./custom-cryptography-handler"); +const cryptographyHandlers = require("./cryptography-handler"); +const errorHandler = require("./error-handler"); + +module.exports = { + getAllFileHandler, + customCryptographyHandlers, + cryptographyHandlers, + errorHandler, +}; diff --git a/src/index.js b/src/index.js new file mode 100644 index 0000000..8617cd0 --- /dev/null +++ b/src/index.js @@ -0,0 +1,15 @@ +const express = require("express"); +const routes = require("./routes"); +require("dotenv").config(); + +const { PORT, HOSTNAME } = require("./environment"); +const { errorHandler } = require("./handlers"); + +const server = express(); +server.use(express.json()); +server.use(routes); +server.use(errorHandler); + +server.listen(PORT, HOSTNAME, () => { + console.log(`Server running at http://${HOSTNAME}:${PORT}/`); +}); diff --git a/src/routes.js b/src/routes.js new file mode 100644 index 0000000..8852bea --- /dev/null +++ b/src/routes.js @@ -0,0 +1,33 @@ +const express = require("express"); + +const { + getAllFileHandler, + customCryptographyHandlers, + cryptographyHandlers, +} = require("./handlers"); + +const router = express.Router(); + +router.get("/", (req, res) => { + return res.json({ + message: "Server is running!", + }); +}); + +// Get All information File +router.get("/getAllFile", getAllFileHandler); + +// Custom routes first +router.post( + "/Base64/encrypting", + customCryptographyHandlers.Base64EncryptHandler +); + +router.post("/SHA3/encrypting", customCryptographyHandlers.SHA3EncryptHandler); + +// Dynamic CryptoJS handlers to encrypting and decrypting +router.post("/:cryptography/encrypting", cryptographyHandlers.encryptHandler); + +router.post("/:cryptography/decrypting", cryptographyHandlers.decryptHandler); + +module.exports = router; diff --git a/src/services/cipher-custom.service.js b/src/services/cipher-custom.service.js new file mode 100644 index 0000000..c6276f4 --- /dev/null +++ b/src/services/cipher-custom.service.js @@ -0,0 +1,13 @@ +const CryptoJS = require("crypto-js"); + +class CipherCustomService { + static toBase64(message) { + return CryptoJS.enc.Base64.parse(message).toString(); + } + + static toSHA3(message, outputLength) { + return CryptoJS.SHA3(message, { outputLength }); + } +} + +module.exports = CipherCustomService; diff --git a/src/services/cipher.service.js b/src/services/cipher.service.js new file mode 100644 index 0000000..fa88985 --- /dev/null +++ b/src/services/cipher.service.js @@ -0,0 +1,42 @@ +const CryptoJS = require("crypto-js"); + +class CipherService { + constructor(cryptography) { + this.cryptography = cryptography; + this.cryptoFunction = this.getCipherFunctionByName(cryptography); + } + + getCipherFunctionByName(cryptography) { + const cryptoFunction = CryptoJS[cryptography]; + + if (!cryptoFunction) { + throw new Error( + `not found cryptography function to ${cryptography} at crypto-js` + ); + } + + return cryptoFunction; + } + + encrypt({ message, secretKey }) { + const handler = this.cryptoFunction.encrypt + ? this.cryptoFunction.encrypt + : this.cryptoFunction; + + return handler(message, secretKey); + } + + decrypt({ message, secretKey }) { + const handler = this.cryptoFunction.decrypt + ? this.cryptoFunction.decrypt + : this.cryptoFunction; + + const decryptedData = handler(message, secretKey).toString( + CryptoJS.enc.Utf8 + ); + + return decryptedData; + } +} + +module.exports = CipherService; diff --git a/src/services/file.service.js b/src/services/file.service.js new file mode 100644 index 0000000..288824c --- /dev/null +++ b/src/services/file.service.js @@ -0,0 +1,15 @@ +const fs = require("fs"); + +class FileService { + static read(path) { + const data = fs.readFileSync(path); + + return data.toString().split("\n"); + } + + static write({ path, data }) { + fs.appendFileSync(path, data + "\n"); + } +} + +module.exports = FileService; diff --git a/src/services/index.js b/src/services/index.js new file mode 100644 index 0000000..3548a4e --- /dev/null +++ b/src/services/index.js @@ -0,0 +1,11 @@ +const FileService = require("./file.service"); +const CipherService = require("./cipher.service"); +const ReadStreamFromCSVService = require("./read-stream-from-csv.service"); +const CipherCustomService = require("./cipher-custom.service"); + +module.exports = { + CipherService, + CipherCustomService, + ReadStreamFromCSVService, + FileService, +}; diff --git a/src/services/read-stream-from-csv.service.js b/src/services/read-stream-from-csv.service.js new file mode 100644 index 0000000..b3186e7 --- /dev/null +++ b/src/services/read-stream-from-csv.service.js @@ -0,0 +1,12 @@ +const fs = require("fs"); +const { parse } = require("csv-parse"); + +class ReadStreamFromCSVService { + static read(filePath) { + return fs + .createReadStream(filePath) + .pipe(parse({ delimiter: ",", from_line: 1 })); + } +} + +module.exports = ReadStreamFromCSVService; diff --git a/src/utils/http-response.js b/src/utils/http-response.js new file mode 100644 index 0000000..0fe4639 --- /dev/null +++ b/src/utils/http-response.js @@ -0,0 +1,22 @@ +class HttpResponse { + constructor(code, message, data, error = false) { + this.code = code; + this.message = message; + this.data = data; + this.error = error; + } + + static ok(message, data) { + return new HttpResponse(200, message, data); + } + + static error(message, statusCode = 400) { + return new HttpResponse(statusCode, message, null, true); + } + + static created(message, data) { + return new HttpResponse(201, message, data); + } +} + +module.exports = HttpResponse; diff --git a/src/utils/index.js b/src/utils/index.js new file mode 100644 index 0000000..ab1c175 --- /dev/null +++ b/src/utils/index.js @@ -0,0 +1,5 @@ +const HttpResponse = require("./http-response"); + +module.exports = { + HttpResponse, +};