crypto-keygen-suite
Version:
Key generation utilities for cryptographic operations. YES I RENAMED IT OMG BASES AND PROTOCOLS!!! See its folder for all <3
34 lines (26 loc) • 1.15 kB
JavaScript
import nacl from 'tweetnacl';
import { randomBytes } from 'crypto';
const args = process.argv.slice(2);
const bitsArg = args.find(arg => arg.startsWith('--bits:'));
const messageArg = args.find(arg => arg.startsWith('--message:'));
if (!bitsArg || !messageArg) {
console.error("Usage: node xchacha20keygen.js --bits:<bits> --message:<message>");
process.exit(1);
}
const bits = parseInt(bitsArg.split(':')[1], 10);
const message = messageArg.split(':')[1];
if (bits !== 256) {
console.error("Only 256 bits are supported for XChaCha20.");
process.exit(1);
}
const key = randomBytes(32); // 32 bytes = 256 bits
const nonce = randomBytes(24); // 24 bytes = 192 bits
const messageBuffer = new TextEncoder().encode(message);
const ciphertext = nacl.secretbox(messageBuffer, nonce, key);
// Convert Buffers to hex strings
const keyHex = key.toString('hex');
const nonceHex = nonce.toString('hex');
const ciphertextHex = Buffer.from(ciphertext).toString('hex');
console.log("Generated Key (HEX):", keyHex);
console.log("Generated Nonce (HEX):", nonceHex);
console.log("Ciphertext (HEX):", ciphertextHex);