crypto-keygen-suite
Version:
Key generation utilities for cryptographic operations. YES I RENAMED IT OMG BASES AND PROTOCOLS!!! See its folder for all <3
54 lines (49 loc) • 1.51 kB
JavaScript
import crypto from 'crypto';
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');
}
const args = process.argv.slice(2);
const method = args[0];
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:', error.message);
process.exit(1);
}