Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
iMrDJAi committed Jun 5, 2021
0 parents commit 53593e6
Show file tree
Hide file tree
Showing 7 changed files with 224 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Auto detect text files and perform LF normalization
* text=auto
21 changes: 21 additions & 0 deletions .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Publish to NPM

on:
release:
types: [created]

jobs:
publish-npm:
runs-on: ubuntu-latest
steps:
- name: Clone repo
uses: actions/checkout@v2
- name: Setup .npmrc file
uses: actions/setup-node@v2
with:
node-version: '12.x'
registry-url: 'https://registry.npmjs.org'
- name: Publish!
run: npm publish
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
package-lock.json
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021 iMrDJAi

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
39 changes: 39 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
***
# AES256 CLI
[![npm](https://img.shields.io/npm/v/aes256-cli?color=red)](https://www.npmjs.com/package/aes256-cli)

[AES256 CLI]: Encrypt/Decrypt with aes256! (by iMrDJAi)
***

## Table of Contents
- [Installation](#installation)
- [Usage](#usage)
- [Notes](#notes)
- [License](#license)

## Installation:
Install this tool from **npm** globally:
```bash
$ npm install aes256-cli -g
```

## Usage:
This is a CLI tool to encrypt and decrypt files and texts, it uses the [aes256](https://github.com/JamesMGreene/node-aes256) Node.js module for that.
The `aes256` module provides a simple way to encrypt/decrypt data, it's based on the built-in `crypto` Node.js module, it uses the aes-256-ctr algorithm.
To get started, run the following command then follow the instructions:

```shell
$ aes256-cli
```
You can also run it directly without installation, with **npx**:
```shell
$ npx aes256-cli
```

## Notes:
Thank you for using AES256 CLI ❤. If you liked it don't forget to leave a star ⭐!

[![GitHub Repo stars](https://img.shields.io/github/stars/iMrDJAi/aes256-cli?style=social)](https://github.com/iMrDJAi/aes256-cli)

## License
[MIT](https://github.com/iMrDJAi/aes256-cli/blob/master/LICENSE) © [iMrDJAi](https://github.com/iMrDJAi)
108 changes: 108 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
#!/usr/bin/env node

;(async () => {

const fs = require('fs')
const aes256 = require('aes256')
const { prompt } = require('inquirer')

console.log('\x1b[33m[AES256 CLI]: Encrypt/Decrypt with aes256! (by iMrDJAi)\x1b[0m')

const { mode } = await prompt({
name: 'mode',
message: 'Select mode',
type: 'list',
choices: ['Encrypt', 'Decrypt']
})

const { type } = await prompt({
name: 'type',
message: 'Select type',
type: 'list',
choices: ['File', 'Text']
})

if (type === 'File') {
var { filename } = await prompt({
name: 'filename',
message: 'Enter your file name to ' + mode.toLowerCase(),
validate: input => input.length > 0
})
if (!fs.existsSync(filename) || !fs.lstatSync(filename).isFile()) return console.log('\x1b[31mFile not found!\x1b[0m')
}

if (type === 'Text') {
var { text } = await prompt({
name: 'text',
message: 'Enter text to ' + mode.toLowerCase(),
type: 'editor',
validate: input => input.length > 0
})
}

const { key } = await prompt({
name: 'key',
message: 'Enter your key',
validate: input => input.length > 0
})

if (type === 'File') {
const input = fs.readFileSync(filename)

if (mode === 'Encrypt') {
try {
var output = aes256.encrypt(key, input)
} catch(err) {
return console.log('\x1b[31m' + err + '\x1b[0m')
}
var prefix = 'encrypted'
}

if (mode === 'Decrypt') {
try {
var output = aes256.decrypt(key, input)
} catch(err) {
return console.log('\x1b[31m' + err + '\x1b[0m')
}
var prefix = 'decrypted'
}

var number = 0
var done = false
while (!done) {
try {
fs.writeFileSync(`${prefix}${number ? number : ''}-${filename}`, output, { flag: 'wx' })
done = true
} catch(err) {
if (err.message.startsWith('EEXIST')) {
number++
} else {
return console.error('\x1b[31m' + err + '\x1b[0m')
}
}
}
}

if (type === 'Text') {
if (mode === 'Encrypt') {
try {
var output = aes256.encrypt(key, text).toString('base64')
} catch(err) {
return console.log('\x1b[31m' + err + '\x1b[0m')
}
}

if (mode === 'Decrypt') {
try {
var output = aes256.decrypt(key, Buffer.from(text, 'base64')).toString()
} catch(err) {
return console.log('\x1b[31m' + err + '\x1b[0m')
}
}

console.log(output)
}

console.log('\x1b[33mDone!\x1b[0m')

})()
31 changes: 31 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"name": "aes256-cli",
"version": "1.0.0",
"description": "[AES256 CLI]: Encrypt/Decrypt with aes256! (by iMrDJAi)",
"bin": "index.js",
"repository": {
"type": "git",
"url": "git+https://github.com/iMrDJAi/aes256-cli.git"
},
"keywords": [
"aes",
"aes256",
"aes-256-ctr",
"cli",
"encrypt",
"decrypt",
"encryption",
"decryption",
"cryptography"
],
"author": "${Mr.DJA}",
"license": "MIT",
"dependencies": {
"aes256": "^1.1.0",
"inquirer": "^8.1.0"
},
"bugs": {
"url": "https://github.com/iMrDJAi/aes256-cli/issues"
},
"homepage": "https://github.com/iMrDJAi/aes256-cli#readme"
}

0 comments on commit 53593e6

Please sign in to comment.