keygentoolshed
Version:
Key generation utilities for cryptographic operations. QUANTUM ENCRYPTION FOLDER UPDATE!!! See its folder for all <3
29 lines (24 loc) • 894 B
JavaScript
import fs from 'fs';
import { program } from 'commander';
function rotateKey(newKey, rotationFile) {
const data = fs.readFileSync(rotationFile, 'utf8');
const keys = JSON.parse(data);
keys[keys.length - 1] = newKey; // Replace the last key with the new key
fs.writeFileSync(rotationFile, JSON.stringify(keys, null, 2));
}
program
.version('1.0.0')
.option('--rotateFile <file>', 'Specify the rotation file', 'rotation.json')
.option('--key <key>', 'Specify the new key to rotate', '')
.parse(process.argv);
const options = program.opts();
if (!options.key) {
console.error('A new key must be specified using --key or -k.');
process.exit(1);
}
try {
rotateKey(options.key, options.rotateFile);
console.log('Key rotated successfully.');
} catch (error) {
console.error('Failed to rotate key:', error.message);
}