UNPKG

keygentoolshed

Version:

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

31 lines (26 loc) 1.2 kB
import { program } from 'commander'; import crypto from 'crypto'; function deriveKeyFromPassword(password, salt, iterations = 100000, keyLength = 32) { return crypto.pbkdf2Sync(password, salt, iterations, keyLength, 'sha256'); } program .version('1.0.0') .description('Derive a key from a password using PBKDF2') .option('-p, --password <password>', 'Password to derive key from') .option('-s, --salt <salt>', 'Salt for the key derivation (hex string)') .option('--iterations <iterations>', 'Number of iterations (default: 100000)', 100000) .option('--key-length <keyLength>', 'Length of the derived key in bytes (default: 32)', 32) .action((options) => { const { password, salt, iterations, keyLength } = options; if (!password || !salt) { console.error('Error: Password and salt are required.'); process.exit(1); } try { const derivedKey = deriveKeyFromPassword(password, Buffer.from(salt, 'hex'), parseInt(iterations), parseInt(keyLength)); console.log(`Derived Key: ${derivedKey}`); } catch (error) { console.error('Error deriving key:', error.message); } }); program.parse(process.argv);