Skip to content

Commit 3273926

Browse files
committed
Merge branch 'release/v1' into main
2 parents e5596c6 + 5947e53 commit 3273926

File tree

9 files changed

+201
-155
lines changed

9 files changed

+201
-155
lines changed

.github/workflows/node.yml

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# This workflow will do a clean install of node dependencies, cache/restore them, build the source code and run tests across different versions of node
2+
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
3+
4+
name: Node.js CI
5+
6+
on:
7+
push:
8+
branches:
9+
- main
10+
- release/*
11+
- devs/*
12+
pull_request:
13+
branches:
14+
- main
15+
- release/*
16+
schedule:
17+
# * is a special character in YAML so you have to quote this string
18+
- cron: '0 2,14 * * *'
19+
release:
20+
types: # This configuration does not affect the page_build event above
21+
- created
22+
23+
jobs:
24+
build:
25+
26+
runs-on: ubuntu-latest
27+
28+
strategy:
29+
matrix:
30+
node-version: [12.x, 14.x, 16.x]
31+
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
32+
33+
steps:
34+
- uses: actions/checkout@v2
35+
- name: Use Node.js ${{ matrix.node-version }}
36+
uses: actions/setup-node@v2
37+
with:
38+
node-version: ${{ matrix.node-version }}
39+
cache: 'npm'
40+
- run: npm install typescript
41+
- run: npm ci
42+
- run: npm run build --if-present
43+
# - run: npm test

README.md

+15-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
# secutilsfiles
2+
23
simple utils to crypt / decrypt files with AES
34

5+
# Usage
6+
7+
`await secutils.files.CryptFile("./text.text", "./text.text.enc", "one")`
8+
9+
`await secutils.files.DecryptFile("./text.text.enc", "./text.text.dec", "one")`
10+
11+
`await secutils.dir.CryptDir("./dir","./dir.enc", "one")`
12+
13+
`await secutils.dir.DecryptDir("./dir.enc","./dir.dec", "one")`
14+
15+
# Building the module :
16+
17+
## Requirements :
418

5-
#
19+
- typescript v3.X or newer

package-lock.json

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

package.json

+13-9
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,30 @@
11
{
22
"name": "secutilsfiles",
3-
"version": "1.0.5",
3+
"version": "2.0.0",
44
"description": "A simple package to crypt and decrypt files",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",
7-
7+
"type": "module",
8+
"keywords": [
9+
"aes",
10+
"files",
11+
"directory",
12+
"crypt",
13+
"decrypt"
14+
],
815
"scripts": {
9-
"prepublish": "tsc",
1016
"start": "tsc && node .",
1117
"build": "tsc",
1218
"test": "node test"
1319
},
14-
1520
"author": "Paul Millet <[email protected]>",
1621
"license": "MIT",
1722
"dependencies": {
18-
"@types/node": "^16.7.2",
23+
"@types/cryptr": "^4.0.1",
24+
"@types/node": "^16.7.5",
1925
"aes256": "^1.1.0",
2026
"cryptr": "^6.0.2",
21-
"dotenv": "^10.0.0",
22-
"typescript": "^4.4.2"
27+
"dotenv": "^10.0.0"
2328
},
2429
"repository": {
2530
"type": "git",
@@ -30,7 +35,6 @@
3035
},
3136
"homepage": "https://github.com/bigopenworld/secutilsfiles/issues",
3237
"devDependencies": {
33-
"@types/cryptr": "^4.0.1",
34-
"typescript": "^2.7.2"
38+
"typescript": "^3.0.0"
3539
}
3640
}

src/dir.ts

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { files, utils } from "./index.js"
2+
3+
/** DecryptFile function
4+
* @param {string} path take the path of the input dir
5+
* @param {string} dest take the path of the destination dir
6+
* @param {string} key take the secret key
7+
* @return {string} Return the key
8+
*/
9+
export async function CryptDir(path : string, dest : string, key : string) : Promise<string> {
10+
let files_list = utils.readDir(path)
11+
;(await files_list).map((e)=> {
12+
files.CryptFile(`${path}/${e}`,`${dest}/${e}`, key)
13+
})
14+
return key
15+
}
16+
17+
/** DecryptFile function
18+
* @param {string} path take the path of the input dir
19+
* @param {string} dest take the path of the destination dir
20+
* @param {string} key take the secret key
21+
* @return {string} Return the key
22+
*/
23+
export async function DecryptDir(path : string, dest : string, key : string) : Promise<string> {
24+
let files_list = utils.readDir(path)
25+
;(await files_list).map((e)=> {
26+
files.DecryptFile(`${path}/${e}`,`${dest}/${e}`, key)
27+
})
28+
return key
29+
}

src/files.ts

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// dependency import
2+
import Cryptr from "cryptr"
3+
import fs from "fs"
4+
import { promisify } from "util"
5+
import * as utils from "./utils.js"
6+
// define const
7+
const readfile = promisify(fs.readFile) // promisify the fs.readFile
8+
const writefile = promisify(fs.writeFile) // promisify the fs.writeFile
9+
10+
/** Read file function
11+
* @param {string} path take the path
12+
* @return {Promise<string>} return promise of data
13+
*/
14+
export async function readFile(path : string) : Promise<string> {
15+
let files : Buffer = await readfile(path)
16+
return files.toString()
17+
}
18+
19+
/** CryptFile function
20+
* @param {string} path take the path of the input file
21+
* @param {string} dest take the path of the destination file
22+
* @param {string | undefined} key take the key if none specified one will be generated
23+
* @return {string} Return the key
24+
*/
25+
export async function CryptFile(path : string, dest : string, key? : string) : Promise<string> {
26+
let enckey = key
27+
if (!enckey) {
28+
enckey = utils.RandomString(20)
29+
}
30+
let crypt = new Cryptr(enckey)
31+
const data = await readFile(path)
32+
const dataenc = crypt.encrypt(data)
33+
await writefile(dest, dataenc)
34+
return enckey
35+
}
36+
37+
/** DecryptFile function
38+
* @param {string} path take the path of the input file
39+
* @param {string} dest take the path of the destination file
40+
* @param {string} key take the secret key
41+
* @return {string} Return the key
42+
*/
43+
export async function DecryptFile(path : string, dest : string, key : string) : Promise<string> {
44+
let enckey = key
45+
let crypt = new Cryptr(enckey)
46+
const data = await readFile(path)
47+
const dataenc = crypt.decrypt(data)
48+
await writefile(dest, dataenc)
49+
return enckey
50+
}

src/index.ts

+6-77
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,7 @@
1-
// dependency import
2-
import Cryptr from "cryptr"
3-
import fs from "fs"
4-
import { promisify } from "util"
5-
6-
// Define const
7-
8-
9-
const readdir = promisify(fs.readdir) // promisify the fs.readdir
10-
const readfile = promisify(fs.readFile) // promisify the fs.readFile
11-
const writefile = promisify(fs.writeFile) // promisify the fs.writeFile
12-
const randomChar = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
13-
const randomcharlengh = randomChar.length;
14-
15-
/** Read dir function
16-
* @param {string} directory take the directory
17-
* @return {Promise<string[]>} return a promise of files path
18-
* Will be use when encrypt dir feature will be created
19-
*/
20-
export async function readDir(directory : string) : Promise<string[]> {
21-
let files = await readdir(directory)
22-
return files.map(file => `${directory}/${file}`)
23-
}
24-
25-
/** Read file function
26-
* @param {string} path take the path
27-
* @return {Promise<string>} return promise of data
28-
*/
29-
export async function readFile(path : string) : Promise<string> {
30-
let files : Buffer = await readfile(path)
31-
return files.toString()
32-
}
33-
34-
/** RandomString function
35-
* @param {number} length take the number of element in your string
36-
* @return {string} Return the random string
37-
*/
38-
export function RandomString(length : number) : string {
39-
var result : string = ""
40-
for ( var i = 0; i < length; i++ ) {
41-
result += randomChar.charAt(Math.floor(Math.random() * randomcharlengh));
42-
}
43-
return result
44-
}
45-
46-
/** CryptFile function
47-
* @param {string} path take the path of the input file
48-
* @param {string} dest take the path of the destination file
49-
* @param {string | undefined} key take the key if none specified one will be generated
50-
* @return {string} Return the key
51-
*/
52-
export async function CryptFile(path : string, dest : string, key? : string) : Promise<string> {
53-
let enckey = key
54-
if (!enckey) {
55-
enckey = RandomString(20)
56-
}
57-
let crypt = new Cryptr(enckey)
58-
const data = await readFile(path)
59-
const dataenc = crypt.encrypt(data)
60-
await writefile(dest, dataenc)
61-
return enckey
62-
}
63-
64-
/** DecryptFile function
65-
* @param {string} path take the path of the input file
66-
* @param {string} dest take the path of the destination file
67-
* @param {string} key take the secret key
68-
* @return {string} Return the key
69-
*/
70-
export async function DecryptFile(path : string, dest : string, key : string) : Promise<string> {
71-
let enckey = key
72-
let crypt = new Cryptr(enckey)
73-
const data = await readFile(path)
74-
const dataenc = crypt.decrypt(data)
75-
await writefile(dest, dataenc)
76-
return enckey
77-
}
1+
// import other files
2+
import * as files from "./files.js"
3+
import * as utils from "./utils.js"
4+
import * as dir from "./dir.js"
785

6+
export {files, utils, dir}
7+
export default {files, utils, dir}

0 commit comments

Comments
 (0)