UNPKG

keygentoolshed

Version:

Key generation utilities for cryptographic operations. QUANTUM ENCRYPTION FOLDER UPDATE!!! See its folder for all <3

65 lines (57 loc) 2.08 kB
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('inputfile', { alias: 'inf', description: 'Path to the file containing the encrypted chunk', type: 'string', demandOption: true }) .option('method', { alias: 'm', description: 'Decryption 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('key', { alias: 'k', description: 'Encryption key in raw format', type: 'string', demandOption: true }) .option('iv', { alias: 'i', description: 'Initialization vector in raw format', type: 'string', demandOption: true }) .option('outputfile', { alias: 'ouf', description: 'Path to save the decrypted chunk', type: 'string', demandOption: true }) .help() .argv; function decryptChunk(inputPath, method, key, iv, outputPath) { const encryptedChunk = fs.readFileSync(inputPath); const keyBuffer = Buffer.from(key, 'binary'); const ivBuffer = Buffer.from(iv, 'binary'); const decipher = crypto.createDecipheriv(method, keyBuffer, ivBuffer); let decrypted = decipher.update(encryptedChunk); decrypted = Buffer.concat([decrypted, decipher.final()]); fs.writeFileSync(outputPath, decrypted); console.log(`Decrypted chunk saved to: ${outputPath}`); } decryptChunk(argv.inputfile, argv.method, argv.key, argv.iv, argv.outputfile);