TOTP Secret Generator

Base32 OTP secrets for authenticator apps

Ad placeholder (leaderboard)

A TOTP secret is the shared key behind every time-based one-time password. When a user enables two-factor authentication, your server generates a random secret, encodes it in base32, and shows it to the user as a QR code. Their authenticator app — Google Authenticator, Authy, 1Password, Microsoft Authenticator — stores that secret and, every 30 seconds, derives a 6-digit code from it using the RFC 6238 algorithm. Because both sides hold the same secret and use the same clock, the codes match without any messages crossing the network. This tool generates a compliant secret, the otpauth:// enrollment URI, and a scannable QR code, all locally.

How it works

The generator produces a fresh secret and packages it for an authenticator app:

  1. Draw 20 random bytes (160 bits) from crypto.getRandomValues.
  2. Encode those bytes in base32 (RFC 4648 alphabet A-Z2-7), the format every authenticator expects.
  3. Build the standard enrollment URI: otpauth://totp/Issuer:label?secret=...&issuer=...&algorithm=SHA1&digits=6&period=30.
  4. Render that URI as a QR code so the app can be enrolled with one scan.

At verification time the app and your server independently compute HOTP(secret, floor(unixTime / 30)) and truncate to 6 digits. No secret travels over the wire after enrollment.

Notes and best practices

  • Store the secret encrypted at rest, tied to the user account; you need it to verify every future code.
  • The default parameters — SHA-1, 6 digits, 30-second period — are the universally supported defaults; only change them if every client you support agrees.
  • A secret of 160 bits is the conventional size and matches the SHA-1 HMAC block length.
  • Everything runs in your browser, so the secret never touches a server during generation. Treat the displayed value as a live credential and clear the screen once enrollment is complete.
Ad placeholder (rectangle)