keygentoolshed
Version:
Key generation utilities for cryptographic operations. QUANTUM ENCRYPTION FOLDER UPDATE!!! See its folder for all <3
56 lines (48 loc) • 1.94 kB
JavaScript
// Btw, if ur reading this, this is the first file i made of the encryptandecrypt folder!!! Also the outputfile shortened to ouf its because i dont want it to be of cuz that can mean a bad thing
import crypto from 'crypto';
import fs from 'fs';
import yargs from 'yargs/yargs';
import { hideBin } from 'yargs/helpers';
const argv = yargs(hideBin(process.argv))
.option('chunk', {
alias: 'c',
description: 'Path to the file containing the chunk to encrypt',
type: 'string',
demandOption: true
})
.option('method', {
alias: 'm',
description: 'Encryption method to use',
type: 'string',
choices: [
'aes-128-cbc', 'aes-192-cbc', 'aes-256-cbc',
'aes-128-xts', 'aes-192-xts', 'aes-256-xts',
'aes-128-gcm', 'aes-192-gcm', 'aes-256-gcm',
'des-ede3-cbc', 'rc4', 'chacha20',
'twofish', 'serpent', 'blowfish',
'cast5', 'idea', 'rc2', 'seed',
'camellia-128-cbc', 'camellia-192-cbc', 'camellia-256-cbc'
],
demandOption: true
})
.option('outputfile', {
alias: 'ouf',
description: 'Path to save the encrypted chunk',
type: 'string',
demandOption: true
})
.help()
.argv;
function encryptChunk(chunkPath, method, outputPath) {
const chunk = fs.readFileSync(chunkPath);
const key = crypto.randomBytes(32);
const iv = crypto.randomBytes(16);
const cipher = crypto.createCipheriv(method, key, iv);
let encrypted = cipher.update(chunk);
encrypted = Buffer.concat([encrypted, cipher.final()]);
fs.writeFileSync(outputPath, encrypted);
console.log(`Encrypted chunk saved to: ${outputPath}`);
console.log('Encryption Key (RAW):', key);
console.log('IV (RAW):', iv);
}
encryptChunk(argv.chunk, argv.method, argv.outputfile);