keygentoolshed
Version:
Key generation utilities for cryptographic operations. QUANTUM ENCRYPTION FOLDER UPDATE!!! See its folder for all <3
57 lines (48 loc) • 1.82 kB
JavaScript
import mceliece from 'mceliece';
import yargs from 'yargs/yargs';
import { hideBin } from 'yargs/helpers';
async function generateMcElieceKeys(size, rawOutput, secure) {
try {
const { publicKey, privateKey } = await mceliece.keyPair(size);
console.log(`McEliece-${size} Key Pair Generated`);
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(`mcelice_${length}_pubkey.raw`, publicKey);
fs.writeFileSync(`mcelice_${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: 8192,
describe: 'McEliece key size (default is 8192 bits)'
})
.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 generateMcElieceKeys(argv.size, argv.rawOutput, argv.secure);
}
main();