shielded-high-encryption
Version:
A secure encryption system using AES, named Shielded High Encryption (SHE)
85 lines (84 loc) • 4.15 kB
JSON
{
"defaultAlgorithm": "aes-256-cbc",
"algorithms": ["aes-256-cbc", "des-ede3-cbc", "rsa"],
"keyLength": 128,
"ivLength": 16,
"rsaKeySize": 2048,
"mainTs": {
"importStatements": [
"import { Encryption } from './index';",
"import fs from 'fs';",
"import yargs from 'yargs';",
"import { hideBin } from 'yargs/helpers';"
],
"yargsConfiguration": {
"encrypt": {
"alias": "e",
"type": "string",
"description": "Text or file to encrypt"
},
"decrypt": {
"alias": "d",
"type": "string",
"description": "File to decrypt"
},
"file": {
"alias": "f",
"type": "boolean",
"description": "Specify if the input is a file"
},
"keyfolder": {
"alias": "k",
"type": "string",
"description": "Folder to save the encrypted key"
},
"dataefile": {
"alias": "ef",
"type": "string",
"description": "File to save the encrypted data"
},
"datadfile": {
"alias": "df",
"type": "string",
"description": "File to save the decrypted data"
},
"algorithm": {
"alias": "a",
"type": "string",
"description": "Encryption algorithm to use (aes-128-cbc, rsa)"
},
"mode": {
"alias": "m",
"type": "string",
"description": "Mode of operation to use (ecb, cbc, cfb, ofb, gcm)",
"choices": ["ecb", "cbc", "cfb", "ofb", "gcm"],
"default": "cbc"
},
"keysize": {
"alias": "ks",
"type": "number",
"description": "Key size to use (128)",
"choices": [128],
"default": 128
},
"rotatekey": {
"alias": "r",
"type": "boolean",
"description": "Rotate the encryption key"
}
},
"encryptionInstance": "const she = new Encryption(argv.algorithm, argv.mode, argv.keysize, argv.dataefile, argv.datadfile);",
"keyFolder": "if (argv.keyfolder) { she.setKeyFolder(argv.keyfolder); }",
"functions": {
"saveKey": "const saveKey = (key: Buffer | string, filename: string) => { she.saveKey(key, filename); };",
"loadKey": "const loadKey = (filename: string): Buffer | string => { return she.loadKey(filename); };"
},
"mainFunction": {
"rotateKey": "if (argv.rotatekey) { await she.rotateKey(); console.log('Encryption key rotated'); }",
"encrypt": "else if (argv.encrypt) { try { const salt = she.generateIv(); const key = she.deriveKeyFromPassword('', salt); const iv = she.generateIv(); saveKey(key, 'key.bin'); saveKey(iv, 'iv.bin'); saveKey(salt, 'salt.bin'); let plaintext; if (argv.file) { plaintext = fs.readFileSync(argv.encrypt, 'utf8'); } else { plaintext = argv.encrypt; } const encryptedText = she.encrypt(plaintext, key, iv); console.log(`Encrypted Text: ${encryptedText}`); } catch (error) { console.error('An error occurred:', error); } }",
"decrypt": "else if (argv.decrypt) { try { const encryptedText = fs.readFileSync(argv.decrypt, 'utf8'); const loadedIv = loadKey('iv.bin') as Buffer; const loadedSalt = loadKey('salt.bin') as Buffer; const derivedKey = she.deriveKeyFromPassword('', loadedSalt); const decryptedText = she.decrypt(encryptedText, derivedKey, loadedIv); console.log(`Decrypted Text: ${decryptedText}`); } catch (error) { console.error('An error occurred:', error); } }",
"default": "else { console.log('Please specify --encrypt or --decrypt'); }"
},
"executeMain": "main();"
}
}