crypto-keygen-suite
Version:
Key generation utilities for cryptographic operations. YES I RENAMED IT. SIX STATE PROTOCOL!!! See its folder for all <3
43 lines (37 loc) • 1.15 kB
JavaScript
import fs from 'fs';
import path from 'path';
function loadKey(filePath) {
try {
const resolvedPath = path.resolve(filePath);
const key = fs.readFileSync(resolvedPath);
console.log('Key loaded successfully.');
return key;
} catch (error) {
console.error('Error loading key:', error.message);
throw error;
}
}
// Command-line argument parsing
const args = process.argv.slice(2);
let filePath = '';
if (args.length === 0) {
console.error('No file path provided. Use --filePath or -fp followed by the file path.');
process.exit(1);
}
for (let i = 0; i < args.length; i++) {
if (args[i] === '--filePath' || args[i] === '-fp') {
filePath = args[i + 1];
break;
}
}
if (!filePath) {
console.error('File path not specified. Use --filePath or -fp followed by the file path.');
process.exit(1);
}
// Load the key
try {
const key = loadKey(filePath);
console.log('Key:', key.toString('utf8')); // Display the key as a UTF-8 string
} catch (error) {
console.error('Failed to load key:', error.message);
}