keygentoolshed
Version:
Key generation utilities for cryptographic operations. QUANTUM ENCRYPTION FOLDER UPDATE!!! See its folder for all <3
986 lines (916 loc) • 27.1 kB
JavaScript
import { program } from 'commander';
import crypto from 'crypto';
import { exec } from 'child_process';
function encryptData(method, key, data, iv) {
const cipher = crypto.createCipheriv(method, Buffer.from(key, 'hex'), Buffer.from(iv, 'hex'));
let encrypted = cipher.update(data, 'utf8', 'hex');
encrypted += cipher.final('hex');
return encrypted;
}
function getKeyLength(method) {
switch (method) {
case 'aes-128-cbc':
case 'aes-128-ecb':
case 'aes-128-gcm':
case 'aes-128-ccm':
case 'aes-128-xts':
case 'aes-128-ofb':
return 16; // 16 bytes
case 'aes-192-cbc':
case 'aes-192-ecb':
case 'aes-192-gcm':
case 'aes-192-ccm':
case 'aes-192-xts':
case 'aes-192-ofb':
return 24; // 24 bytes
case 'aes-256-cbc':
case 'aes-256-ecb':
case 'aes-256-gcm':
case 'aes-256-ccm':
case 'aes-256-xts':
case 'aes-256-ofb':
return 32; // 32 bytes
case 'des-ede3-cbc':
return 24; // 24 bytes
case 'rc4':
return 16; // 16 bytes
case 'blowfish-cbc':
return 32; // 32 bytes
case 'cast5-cbc':
return 16; // 16 bytes
default:
throw new Error('Unsupported encryption method.');
}
}
function generateHexKey(length) {
return crypto.randomBytes(length).toString('hex');
}
function generateECCKeyPair() {
const { publicKey, privateKey } = crypto.generateKeyPairSync('ec', {
namedCurve: 'secp256k1',
});
console.log('ECC Public Key:\n', publicKey.export({ type: 'spki', format: 'pem' }));
console.log('ECC Private Key:\n', privateKey.export({ type: 'pkcs8', format: 'pem' }));
}
program
.version('1.0.0')
.description('A simple CLI for encrypting data and generating keys');
program
.command('encrypt <data>')
.option('-m, --method <type>', 'encryption method (e.g., aes-256-cbc, aes-256-gcm, etc.)')
.option('-k, --key <key>', 'key for encryption (must be appropriate length for the method)')
.option('-i, --iv <iv>', 'initialization vector (hex string)')
.action((data, options) => {
const method = options.method || 'aes-256-gcm';
const key = options.key || '';
const iv = options.iv || crypto.randomBytes(16).toString('hex');
try {
const encryptedData = encryptData(method, key, data, iv);
console.log(`IV: ${iv}`);
console.log(`Encrypted Data: ${encryptedData}`);
} catch (error) {
console.error('Error encrypting data:', error.message);
}
});
program
.command('generate-key <method>')
.action((method) => {
try {
const keyLength = getKeyLength(method);
const generatedKey = generateHexKey(keyLength);
console.log(`Generated Key for ${method} (${keyLength * 2} characters): ${generatedKey}`);
} catch (error) {
console.error('Error generating key:', error.message);
}
});
program
.command('generate-ecc-key')
.action(() => {
try {
generateECCKeyPair();
} catch (error) {
console.error('Error generating ECC key pair:', error.message);
}
});
program
.command('generate-hex-key <method>')
.action((method) => {
try {
const keyLength = getKeyLength(method);
const hexKey = generateHexKey(keyLength);
console.log(`Generated Hex Key for ${method} (${keyLength * 2} characters): ${hexKey}`);
} catch (error) {
console.error('Error generating hex key:', error.message);
}
});
program
.command('generate-keypair')
.action(() => {
exec('node ./keyPairGenerator.js', (error, stdout, stderr) => {
if (error) {
console.error(`Error executing key pair generator: ${error.message}`);
return;
}
if (stderr) {
console.error(`Error: ${stderr}`);
return;
}
console.log(stdout);
});
});
program
.command('generate-keys')
.action(() => {
exec('node ./keyPairGenerator.js', (error, stdout, stderr) => {
if (error) {
console.error(`Error executing key generator: ${error.message}`);
return;
}
if (stderr) {
console.error(`Error: ${stderr}`);
return;
}
console.log(stdout);
});
});
program
.command('generate-pem')
.action(() => {
exec('node ./pemGenerator.js', (error, stdout, stderr) => {
if (error) {
console.error(`Error executing PEM generator: ${error.message}`);
return;
}
if (stderr) {
console.error(`Error: ${stderr}`);
return;
}
console.log(stdout);
});
});
program
.command('generate-pem-keypair')
.action(() => {
exec('node ./pemKeyPairGenerator.js', (error, stdout, stderr) => {
if (error) {
console.error(`Error executing PEM key pair generator: ${error.message}`);
return;
}
if (stderr) {
console.error(`Error: ${stderr}`);
return;
}
console.log(stdout);
});
});
program
.command('generate-pem-keys')
.action(() => {
exec('node ./pemKeyPairGenerator.js', (error, stdout, stderr) => {
if (error) {
console.error(`Error executing PEM keys generator: ${error.message}`);
return;
}
if (stderr) {
console.error(`Error: ${stderr}`);
return;
}
console.log(stdout);
});
});
program
.command('generate-pem-keypair-async')
.action(() => {
exec('node ./pemKeyPairGeneratorAsync.js', (error, stdout, stderr) => {
if (error) {
console.error(`Error executing PEM key pair async generator: ${error.message}`);
return;
}
if (stderr) {
console.error(`Error: ${stderr}`);
return;
}
console.log(stdout);
});
});
program
.command('generate-pem-keys-async')
.action(() => {
exec('node ./pemKeyPairGeneratorAsync.js', (error, stdout, stderr) => {
if (error) {
console.error(`Error executing PEM keys async generator: ${error.message}`);
return;
}
if (stderr) {
console.error(`Error: ${stderr}`);
return;
}
console.log(stdout);
});
});
program
.command('generate-ecc-key')
.action(() => {
exec('node ./eccKeyGenerator.js', (error, stdout, stderr) => {
if (error) {
console.error(`Error executing ECC key generator: ${error.message}`);
return;
}
if (stderr) {
console.error(`Error: ${stderr}`);
return;
}
console.log(stdout);
});
});
program
.command('generate-aes-key <method>')
.action((method) => {
exec(`node ./aesKeyGenerator.js ${method}`, (error, stdout, stderr) => {
if (error) {
console.error(`Error executing AES key generator: ${error.message}`);
return;
}
if (stderr) {
console.error(`Error: ${stderr}`);
return;
}
console.log(stdout);
});
});
program
.command('generate-hmac-key')
.action(() => {
exec('node ./hmacKeyGenerator.js', (error, stdout, stderr) => {
if (error) {
console.error(`Error executing HMAC key generator: ${error.message}`);
return;
}
if (stderr) {
console.error(`Error: ${stderr}`);
return;
}
console.log(stdout);
});
});
program
.command('jwt-token-generator')
.action(() => {
exec('node ./jwtTokenGenerator.js', (error, stdout, stderr) => {
if (error) {
console.error(`Error executing JWT token generator: ${error.message}`);
return;
}
if (stderr) {
console.error(`Error: ${stderr}`);
return;
}
console.log(stdout);
});
});
program
.command('jwk-generator')
.action(() => {
exec('node ./jwkGenerator.js', (error, stdout, stderr) => {
if (error) {
console.error(`Error executing JWK generator: ${error.message}`);
return;
}
if (stderr) {
console.error(`Error: ${stderr}`);
return;
}
console.log(stdout);
});
});
program
.command('pbkdf2-key-generator ')
.action(() => {
exec('node ./pbkdf2keyGenerator.js', (error, stdout, stderr) => {
if (error) {
console.error(`Error executing PBKDF2 key generator: ${error.message}`);
return;
}
if (stderr) {
console.error(`Error: ${stderr}`);
return;
}
console.log(stdout);
});
});
program
.command('argon2-password-hash')
.action(() => {
exec('node ./argon2PassHash.js', (error, stdout, stderr) => {
if (error) {
console.error(`Error executing Argon2 password hash: ${error.message}`);
return;
}
if (stderr) {
console.error(`Error: ${stderr}`);
return;
}
console.log(stdout);
});
});
program
.command('hkdf-key-derivation')
.action(() => {
exec('node ./hkdfKeyDriver.js', (error, stdout, stderr) => {
if (error) {
console.error(`Error executing HKDF key derivation: ${error.message}`);
return;
}
if (stderr) {
console.error(`Error: ${stderr}`);
return;
}
console.log(stdout);
});
});
program
.command('dsa-key-generator')
.action(() => {
exec('node ./DSAKeyGenerator.js', (error, stdout, stderr) => {
if (error) {
console.error(`Error executing DSA key generator: ${error.message}`);
return;
}
if (stderr) {
console.error(`Error: ${stderr}`);
return;
}
console.log(stdout);
});
});
program
.command('chacha20-key-generator')
.action(() => {
exec('node ./ChaCha20KeyGenerator.js', (error, stdout, stderr) => {
if (error) {
console.error(`Error executing ChaCha20 key generator: ${error.message}`);
return;
}
if (stderr) {
console.error(`Error: ${stderr}`);
return;
}
console.log(stdout);
});
});
program
.command('fish-family-generator')
.action(() => {
exec('node ./fishGenerator.js', (error, stdout, stderr) => {
if (error) {
console.error(`Error executing fishes key generator: ${error.message}`);
return;
}
if (stderr) {
console.error(`Error: ${stderr}`);
return;
}
console.log(stdout);
});
});
program
.command('generate-diffie-hellman-keys')
.action(() => {
exec('node ./generateDHKeys.js', (error, stdout, stderr) => {
if (error) {
console.error(`Error executing Diffie Hellman key generator: ${error.message}`);
return;
}
if (stderr) {
console.error(`Error: ${stderr}`);
return;
}
console.log(stdout);
});
});
program
.command('generate-otp')
.action(() => {
exec('node ./generateOTP.js', (error, stdout, stderr) => {
if (error) {
console.error(`Error executing the OTP generator: ${error.message}`);
return;
}
if (stderr) {
console.error(`Error: ${stderr}`);
return;
}
console.log(stdout);
});
});
program
.command('compress-data')
.action(() => {
exec('node ./compressData.js', (error, stdout, stderr) => {
if (error) {
console.error(`Error compressing data: ${error.message}`);
return;
}
if (stderr) {
console.error(`Error: ${stderr}`);
return;
}
console.log(stdout);
});
});
program
.command('decompress-data')
.action(() => {
exec('node ./decompressData.js', (error, stdout, stderr) => {
if (error) {
console.error(`Error decompressing data: ${error.message}`);
return;
}
if (stderr) {
console.error(`Error: ${stderr}`);
return;
}
console.log(stdout);
});
});
program
.command('generate-shares')
.action(() => {
exec('node ./generateShares.js', (error, stdout, stderr) => {
if (error) {
console.error(`Error generating shares: ${error.message}`);
return;
}
if (stderr) {
console.error(`Error: ${stderr}`);
return;
}
console.log(stdout);
});
});
program
.command('reconstruct-shares')
.action(() => {
exec('node ./reconstructShares.js', (error, stdout, stderr) => {
if (error) {
console.error(`Error reconstructing shares: ${error.message}`);
return;
}
if (stderr) {
console.error(`Error: ${stderr}`);
return;
}
console.log(stdout);
});
});
program
.command('derive-key-from-password')
.action(() => {
exec('node ./deriveKeyFromPassword.js', (error, stdout, stderr) => {
if (error) {
console.error(`Error deriving the key from the password: ${error.message}`);
return;
}
if (stderr) {
console.error(`Error: ${stderr}`);
return;
}
console.log(stdout);
});
});
program
.command('load-key')
.action(() => {
exec('node ./loadKey.js', (error, stdout, stderr) => {
if (error) {
console.error(`Error loading the key: ${error.message}`);
return;
}
if (stderr) {
console.error(`Error: ${stderr}`);
return;
}
console.log(stdout);
});
});
program
.command('save-key')
.action(() => {
exec('node ./saveKey.js', (error, stdout, stderr) => {
if (error) {
console.error(`Error saving your key: ${error.message}`);
return;
}
if (stderr) {
console.error(`Error: ${stderr}`);
return;
}
console.log(stdout);
});
});
program
.command('rotate-key')
.action(() => {
exec('node ./rotateKey.js', (error, stdout, stderr) => {
if (error) {
console.error(`Error rotating your key: ${error.message}`);
return;
}
if (stderr) {
console.error(`Error: ${stderr}`);
return;
}
console.log(stdout);
});
});
program
.command('gs1-key-generator')
.action(() => {
exec('node ./gs1keygenerator.js', (error, stdout, stderr) => {
if (error) {
console.error(`Error generating your gs1 key: ${error.message}`);
return;
}
if (stderr) {
console.error(`Error: ${stderr}`);
return;
}
console.log(stdout);
});
});
program
.command('ed25519-key-generator')
.action(() => {
exec('node ./ed25519keygensingle.js', (error, stdout, stderr) => {
if (error) {
console.error(`Error generating your ed25519 key: ${error.message}`);
return;
}
if (stderr) {
console.error(`Error: ${stderr}`);
return;
}
console.log(stdout);
});
});
program
.command('xchacha20-key-generator')
.action(() => {
exec('node ./xchacha20keygen.js', (error, stdout, stderr) => {
if (error) {
console.error(`Error generating your XChaCha20 key: ${error.message}`);
return;
}
if (stderr) {
console.error(`Error: ${stderr}`);
return;
}
console.log(stdout);
});
});
program
.command('serpent-key-generator')
.action(() => {
exec('node ./serpentKeyGenerator.js', (error, stdout, stderr) => {
if (error) {
console.error(`Error generating your Serpent key: ${error.message}`);
return;
}
if (stderr) {
console.error(`Error: ${stderr}`);
return;
}
console.log(stdout);
});
});
program
.command('camellia-key-generator')
.action(() => {
exec('node ./camellia-key-gen.js', (error, stdout, stderr) => {
if (error) {
console.error(`Error generating your Camellia key: ${error.message}`);
return;
}
if (stderr) {
console.error(`Error: ${stderr}`);
return;
}
console.log(stdout);
});
});
program
.command('sha-key-generator')
.action(() => {
exec('node ./shaKeyGenerator.js', (error, stdout, stderr) => {
if (error) {
console.error(`Error generating your SHA key: ${error.message}`);
return;
}
if (stderr) {
console.error(`Error: ${stderr}`);
return;
}
console.log(stdout);
});
});
program
.command('split-shares')
.action(() => {
exec('node ./splitShares.js', (error, stdout, stderr) => {
if (error) {
console.error(`Error splitting your shares: ${error.message}`);
return;
}
if (stderr) {
console.error(`Error: ${stderr}`);
return;
}
console.log(stdout);
});
});
program
.command('validate-shares')
.action(() => {
exec('node ./validateShares.js', (error, stdout, stderr) => {
if (error) {
console.error(`Error validating your shares: ${error.message}`);
return;
}
if (stderr) {
console.error(`Error: ${stderr}`);
return;
}
console.log(stdout);
});
});
program
.command('combine-shares')
.action(() => {
exec('node ./combineShares.js', (error, stdout, stderr) => {
if (error) {
console.error(`Error combining your shares: ${error.message}`);
return;
}
if (stderr) {
console.error(`Error: ${stderr}`);
return;
}
console.log(stdout);
});
});
program
.command('add-metadata')
.action(() => {
exec('node ./addMetadata.js', (error, stdout, stderr) => {
if (error) {
console.error(`Error adding metadata: ${error.message}`);
return;
}
if (stderr) {
console.error(`Error: ${stderr}`);
return;
}
console.log(stdout);
});
});
program
.command('xptag')
.action(() => {
exec('node ./xptag.js', (error, stdout, stderr) => {
if (error) {
console.error(`Error executing xptag generator: ${error.message}`);
return;
}
if (stderr) {
console.error(`Error: ${stderr}`);
return;
}
console.log(stdout);
});
});
program
.command('she-key-generator')
.action(() => {
exec('node ./sheKeyGenerator.js', (error, stdout, stderr) => {
if (error) {
console.error(`Error executing SHE key generator: ${error.message}`);
return;
}
if (stderr) {
console.error(`Error: ${stderr}`);
return;
}
console.log(stdout);
});
});
program
.command('encrypt-chunk')
.action(() => {
exec('node ./encryptChunk.js', (error, stdout, stderr) => {
if (error) {
console.error(`Error encrypting your chunk: ${error.message}`);
return;
}
if (stderr) {
console.error(`Error: ${stderr}`);
return;
}
console.log(stdout);
});
});
program
.command('decrypt-chunk')
.action(() => {
exec('node ./decryptChunk.js', (error, stdout, stderr) => {
if (error) {
console.error(`Error decrypting your chunk: ${error.message}`);
return;
}
if (stderr) {
console.error(`Error: ${stderr}`);
return;
}
console.log(stdout);
});
});
program
.command('generate-iv')
.action(() => {
exec('node ./generateIv.js', (error, stdout, stderr) => {
if (error) {
console.error(`Error generating your IV: ${error.message}`);
return;
}
if (stderr) {
console.error(`Error: ${stderr}`);
return;
}
console.log(stdout);
});
});
program
.command('caesar-cipher-generator')
.action(() => {
exec('node ./caesarciphergenerator.js', (error, stdout, stderr) => {
if (error) {
console.error(`Error generating your Caesar Cipher: ${error.message}`);
return;
}
if (stderr) {
console.error(`Error: ${stderr}`);
return;
}
console.log(stdout);
});
});
program
.command('vigenere-cipher-generator')
.action(() => {
exec('node ./vigenereciphergenerator.js', (error, stdout, stderr) => {
if (error) {
console.error(`Error generating your Vigenère Cipher: ${error.message}`);
return;
}
if (stderr) {
console.error(`Error: ${stderr}`);
return;
}
console.log(stdout);
});
});
program
.command('rail-fence-cipher-generator')
.action(() => {
exec('node ./railFenceCipherGenerator.js', (error, stdout, stderr) => {
if (error) {
console.error(`Error generating your Rail Fence Cipher: ${error.message}`);
return;
}
if (stderr) {
console.error(`Error: ${stderr}`);
return;
}
console.log(stdout);
});
});
program
.command('atbash-cipher-generator')
.action(() => {
exec('node ./atbashciphergenerator.js', (error, stdout, stderr) => {
if (error) {
console.error(`Error generating your Atbash Cipher: ${error.message}`);
return;
}
if (stderr) {
console.error(`Error: ${stderr}`);
return;
}
console.log(stdout);
});
});
program
.command('columnar-transposition-cipher-generator')
.action(() => {
exec('node ./columnartranspositionciphergenerator.js', (error, stdout, stderr) => {
if (error) {
console.error(`Error generating your Columnar Transposition Cipher: ${error.message}`);
return;
}
if (stderr) {
console.error(`Error: ${stderr}`);
return;
}
console.log(stdout);
});
});
program
.command('dilithum-key-generator')
.action(() => {
exec('node ./dilithiumKeyGen.js', (error, stdout, stderr) => {
if (error) {
console.error(`Error generating your Dilithium key: ${error.message}`);
return;
}
if (stderr) {
console.error(`Error: ${stderr}`);
return;
}
console.log(stdout);
});
});
program
.command('falcon-key-generator')
.action(() => {
exec('node ./falconKeyGen.js', (error, stdout, stderr) => {
if (error) {
console.error(`Error generating your FALCON key: ${error.message}`);
return;
}
if (stderr) {
console.error(`Error: ${stderr}`);
return;
}
console.log(stdout);
});
});
program
.command('kyber-key-generator')
.action(() => {
exec('node ./kyberKeyGen.js', (error, stdout, stderr) => {
if (error) {
console.error(`Error generating your Kyber key: ${error.message}`);
return;
}
if (stderr) {
console.error(`Error: ${stderr}`);
return;
}
console.log(stdout);
});
});
program
.command('mceliece-key-generator')
.action(() => {
exec('node ./mceliceKeyGen.js', (error, stdout, stderr) => {
if (error) {
console.error(`Error generating your McEliece key: ${error.message}`);
return;
}
if (stderr) {
console.error(`Error: ${stderr}`);
return;
}
console.log(stdout);
});
});
program
.command('sidh-key-generator')
.action(() => {
exec('node ./sidhkeygen.js', (error, stdout, stderr) => {
if (error) {
console.error(`Error generating your SIDH key: ${error.message}`);
return;
}
if (stderr) {
console.error(`Error: ${stderr}`);
return;
}
console.log(stdout);
});
});
program
.command('sphincsplus-key-generator')
.action(() => {
exec('node ./sphincspluskeygen.js', (error, stdout, stderr) => {
if (error) {
console.error(`Error generating your SPHINCS+ key: ${error.message}`);
return;
}
if (stderr) {
console.error(`Error: ${stderr}`);
return;
}
console.log(stdout);
});
});
program.parse(process.argv);