Skip to content

Commit 6f3edee

Browse files
committed
Tanmay Vij | AES Encryptor-Decryptor/ | CLI based Encryption tool
1 parent 41ca159 commit 6f3edee

File tree

5 files changed

+343
-0
lines changed

5 files changed

+343
-0
lines changed

AES Encryptor-Decryptor/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules/

AES Encryptor-Decryptor/README.md

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# AES Encryption/Decryption Tool built in NodeJS
2+
3+
### Requirements
4+
- NodeJS
5+
- NPM
6+
### Running
7+
```sh
8+
$ cd AES\ Encryptor-Decryptor/
9+
$ npm start
10+
```
11+
12+
### Contributor
13+
14+
[tanmayvij](https://github.com/tanmayvij)

AES Encryptor-Decryptor/app.js

+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
const crypto = require('crypto');
2+
const prompt = require('prompt');
3+
const algorithm = 'aes-256-ctr';
4+
5+
let password;
6+
let iv = crypto.createHash('sha256').update(String("vsdjkdhg")).digest('base64').substr(0, 16);
7+
8+
const decrypt = () => {
9+
10+
try
11+
{
12+
prompt.get({name: "encrypted", message: "Encrypted String"}, (error, result) => {
13+
if(!error)
14+
{
15+
let encrypted = result.encrypted;
16+
prompt.get("Password", (err, result) => {
17+
if(!err)
18+
{
19+
password = result.Password;
20+
const decipher = crypto.createDecipheriv(algorithm,password, iv);
21+
let dec = decipher.update(encrypted,'hex','utf8');
22+
dec += decipher.final('utf8');
23+
console.log("Decrypted String: ", dec);
24+
}
25+
});
26+
}
27+
});
28+
}
29+
catch(e)
30+
{
31+
console.error(e);
32+
}
33+
34+
}
35+
36+
const encrypt = () => {
37+
38+
try
39+
{
40+
prompt.get({name: "string", message: "Enter the String"}, (error, result) => {
41+
if(!error)
42+
{
43+
let string = result.string;
44+
prompt.get({name: "password", message: "Choose a password (32 characters)"}, (err, result) => {
45+
if(!err)
46+
{
47+
password = result.password;
48+
const cipher = crypto.createCipheriv(algorithm, password, iv);
49+
let enc = cipher.update(string, 'utf8', 'hex');
50+
enc += cipher.final('hex');
51+
console.log("Encrypted String: ", enc);
52+
}
53+
});
54+
}
55+
});
56+
}
57+
catch(e)
58+
{
59+
console.error(e);
60+
}
61+
}
62+
63+
64+
prompt.start();
65+
66+
console.log("Encrypt/Decrypt Text using AES 256-bit Encryption\n");
67+
68+
console.log("1. Encrypt");
69+
console.log("2. Decrypt");
70+
71+
prompt.get({name: "choice", message: "Please enter your choice (1/2)"}, (err, result) => {
72+
if(!err)
73+
{
74+
switch(parseInt(result.choice))
75+
{
76+
case 1: encrypt(); break;
77+
case 2: decrypt(); break;
78+
default: console.log("Invalid input.");
79+
}
80+
}
81+
});

AES Encryptor-Decryptor/package-lock.json

+231
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

AES Encryptor-Decryptor/package.json

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"name": "aes-encryptor-decryptor",
3+
"version": "1.0.0",
4+
"description": "AES Encryption/Decryption tool built in NodeJS",
5+
"main": "index.js",
6+
"devDependencies": {},
7+
"scripts": {
8+
"start": "node app",
9+
"test": "echo \"Error: no test specified\" && exit 1"
10+
},
11+
"author": "Tanmay Vij",
12+
"license": "ISC",
13+
"dependencies": {
14+
"prompt": "^1.0.0"
15+
}
16+
}

0 commit comments

Comments
 (0)