Secret Key Generator

Generate cryptographically secure secrets for session management, API authentication, and other security-sensitive applications.

Entropy:256 bits
256 bits
256 bits
256 bits
256 bits
256 bits

Common Uses

.env
# Session secret
SESSION_SECRET=...

# Cookie signing secret
COOKIE_SECRET=...

# CSRF token secret
CSRF_SECRET=...
Express.js session
const session = require('express-session');

app.use(session({
  secret: process.env.SESSION_SECRET,
  resave: false,
  saveUninitialized: false,
  cookie: { 
    secure: true,
    httpOnly: true,
    maxAge: 24 * 60 * 60 * 1000 // 24 hours
  }
}));

Choosing secret length

  • 128 bits (16 bytes): Minimum for most applications
  • 256 bits (32 bytes): Recommended for session secrets
  • 512 bits (64 bytes): Maximum security for sensitive operations

Bulk Generation

secrets

Generate in Terminal

Base64

$openssl rand -base64 32

Hexadecimal

$openssl rand -hex 32

URL-safe (Python)

$python3 -c "import secrets; print(secrets.token_urlsafe(32))"

Node.js

$node -e "console.log(require('crypto').randomBytes(32).toString('base64'))"