npm package
@bturkis/keygen
Cryptographically secure key generators for Node.js, Deno, and browsers. Uses Web Crypto API with rejection sampling — zero bias.
npm
npm install @bturkis/keygenpnpm
pnpm add @bturkis/keygenyarn
yarn add @bturkis/keygen8Functions
0Dependencies*
<8KBGzipped
ESM+CJSFormats
* except uuid for UUID v4
What's Included
Password Generator
Secure passwords with character class guarantee
generatePassword({ length: 16 })Hex Key Generator
Cryptographic hex keys with prefix/suffix support
generateHexKey({ bytes: 32, prefix: "sk_" })UUID v4 Generator
RFC 4122 compliant unique identifiers
generateUUID({ count: 5 })Secret Key Generator
High-entropy keys with mixed characters
generateSecretKey({ length: 64 })Random String Generator
Alphanumeric strings safe for URLs and DBs
generateRandomString({ length: 24 })Text to Key (SHA)
Deterministic hash using SHA-256/384/512
await textToKey("hello world")Code Examples
Quick Start
import { generatePassword, generateHexKey } from "@bturkis/keygen";
// Secure password (character class guaranteed)
const [password] = generatePassword({ length: 16 });
// API key with prefix
const [apiKey] = generateHexKey({ bytes: 32, prefix: "sk_live_" });
// Bulk generation
const passwords = generatePassword({ length: 20, count: 100 });Password Options
import { generatePassword, checkPasswordStrength } from "@bturkis/keygen";
// Only letters and numbers (no symbols)
const simple = generatePassword({ length: 12, symbols: false });
// Custom special characters
const custom = generatePassword({ customSymbols: "!@#$" });
// Minimum entropy enforcement
const secure = generatePassword({ length: 20, minEntropy: 128 });
// Check any password's strength
const strength = checkPasswordStrength("MyP@ssw0rd");
// => { score: 90, rating: "very-strong", issues: [] }Hashing & Entropy
import { textToKey, calculateEntropy } from "@bturkis/keygen";
// SHA-256 hash
const hash = await textToKey("hello world");
// => "b94d27b9934d3e08..."
// SHA-512 hash
const hash512 = await textToKey("hello", { algorithm: "SHA-512" });
// Calculate entropy
const info = calculateEntropy({ bytes: 32 });
// => { bits: 256, strength: "very-strong" }API Reference
Full documentation for all 8 functions with TypeScript signatures, parameters, and code examples.
View API Documentation →Security
✅crypto.getRandomValues() — Web Crypto API
✅Rejection sampling — zero modulo bias
✅Character class guarantee for passwords
✅Memory zeroing — TypedArrays cleared after use
✅Minimum entropy enforcement (optional)
✅Tree-shakeable ESM + CJS with TypeScript types