keygentoolshed
Version:
Key generation utilities for cryptographic operations. QUANTUM ENCRYPTION FOLDER UPDATE!!! See its folder for all <3
66 lines (57 loc) • 2.29 kB
JavaScript
import { Sphincs } from 'sphincs'; // Ensure you install the package
import yargs from 'yargs/yargs';
import { hideBin } from 'yargs/helpers';
async function generateSphincsKeys(securityLevel, hash, rawOutput, secure) {
try {
const sphincs = new Sphincs(securityLevel, hash);
const { publicKey, privateKey } = sphincs.keyPair();
console.log(`SPHINCS+ Key Pair Generated (Security Level: ${securityLevel}, 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(`sphincsplus_${length}_pubkey.raw`, publicKey);
fs.writeFileSync(`sphincsplus_${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('securityLevel', {
alias: 's',
type: 'string',
default: 'fast',
choices: ['fast', 'small', 'robust'],
describe: 'Choose SPHINCS+ security mode (fast, small, or robust)'
})
.option('hash', {
alias: 'h',
type: 'string',
default: 'SHA256',
choices: ['SHA256', 'SHAKE256'],
describe: 'Hash function used in SPHINCS+'
})
.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 generateSphincsKeys(argv.securityLevel, argv.hash, argv.rawOutput, argv.secure);
}
main();