UNPKG

keygentoolshed

Version:

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

66 lines (57 loc) 2.22 kB
import { Dilithium } from 'dilithium-crystals'; import yargs from 'yargs/yargs'; import { hideBin } from 'yargs/helpers'; async function generateDilithiumKeys(size, hash, rawOutput, secure) { try { const dilithium = new Dilithium(size, hash); const { publicKey, privateKey } = dilithium.keyPair(); console.log(`Dilithium-${size} Key Pair Generated (Hash: ${hash})`); if (rawOutput) { console.log(`Public Key (RAW):`, publicKey); console.log(`Private Key (RAW):`, privateKey); } else { console.log(`Public Key (HEX): ${Buffer.from(publicKey).toString('hex')}`); console.log(`Private Key (HEX): ${Buffer.from(privateKey).toString('hex')}`); } if (secure) { console.log("Secure Mode Enabled: Keys will be stored in a protected file."); fs.writeFileSync(`dilithium_${length}_pubkey.raw`, publicKey); fs.writeFileSync(`dilithium_${length}_privkey.raw`, privateKey); } return { publicKey, privateKey }; } catch (error) { console.error(`Key Generation Failed: ${error.message}`); } } async function main() { const argv = yargs(hideBin(process.argv)) .option('size', { alias: 's', type: 'number', default: 3, choices: [2, 3, 5], // NIST-recommended parameter sets describe: 'Dilithium parameter set (2, 3, or 5)' }) .option('hash', { alias: 'h', type: 'string', default: 'SHA3', choices: ['SHA3', 'Shake256'], describe: 'Hash function used in signing' }) .option('rawOutput', { alias: 'r', type: 'boolean', default: false, describe: 'Output keys in raw format' }) .option('secure', { alias: 'p', type: 'boolean', default: false, describe: 'Enable secure key storage' }) .argv; await generateDilithiumKeys(argv.size, argv.hash, argv.rawOutput, argv.secure); } main();