Xerobit

TOTP Generator: Compute 2FA Codes from a Base32 Secret

Enter a Base32 secret to generate the current TOTP code, see how many seconds remain in the period, and preview the next code. This totp generator implements RFC 6238 and RFC 4226 with pure TypeScript cryptography. Everything runs locally in your browser so nothing is uploaded to any server.

Result

  • Current code
    404009
  • Seconds remaining
    9
  • Next code
    448045
  • Time step (counter)
    59797585

Do not paste live production secrets into any tool. This totp generator runs locally in your browser.

How to use the totp generator

  1. Paste your Base32 secret into the Base32 secret field. Spaces are stripped automatically.
  2. Choose the number of digits (6 or 8) and the period in seconds (usually 30).
  3. Select the hash algorithm. Most authenticator apps use SHA-1 by default.
  4. Optionally enter a specific Unix time to reproduce test vectors or debug past codes.
  5. Read the generated code, the remaining seconds in the current window, and the upcoming code.

How TOTP works under the hood

TOTP (Time-based One-Time Password) extends HOTP by replacing the event counter with a time step. The algorithm defined in RFC 6238 computes a counter value as C = floor(T / period), where T is the Unix time in seconds. That counter is encoded as an 8-byte big-endian integer and passed to HMAC along with the shared secret.

The HMAC output is then truncated per RFC 4226. Take the last nibble of the hash as an offset, read four bytes starting at that offset, mask the high bit, and take the result modulo 10^digits. For example, with the RFC 6238 SHA-1 test secret 12345678901234567890 (Base32: GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ), at time 59 the counter is floor(59/30) = 1. The 8-digit code produced is 94287082, and the 6-digit truncation is 287082.

RFC 6238 test vectors reference

Use these known values to verify any totp calculator or authenticator implementation. The SHA-1 secret is the ASCII string 12345678901234567890 encoded in Base32. The SHA-256 secret repeats that string to 32 bytes, and the SHA-512 secret repeats it to 64 bytes.

TimeAlgorithmDigitsExpected Code
59SHA-1894287082
59SHA-16287082
1111111109SHA-1807081804
1234567890SHA-1889005924
2000000000SHA-1869279037
59SHA-256846119246
59SHA-512890693936
1111111109SHA-512825091201
1234567890SHA-512893441116

Setting the period to 1 second and the time to 0 turns this totp generator into an HOTP tool. With counter 0, the SHA-1 secret above yields the RFC 4226 code 755224.

Practical uses for a TOTP code generator

Developers building two-factor authentication need a reliable 2fa code generator to test their server-side verification logic without scanning QR codes into a phone every time. By entering the same Base32 secret your backend stores, you can instantly produce matching codes to assert against.

Security auditors also use tools like this to confirm that applications follow RFC 6238 correctly, including proper handling of clock drift and time-step boundaries. If you work with financial identifiers such as those checked by a credit card checker or an iban checker, pairing them with strong TOTP-based two-factor authentication adds a critical layer of account security.

Common mistakes when generating TOTP codes

The most frequent error is providing a hex-encoded secret instead of Base32. Authenticator apps expect RFC 4648 Base32. Another common issue is clock skew: if your device clock drifts more than half a period away from the server, the codes will not match. Most servers allow a window of one step before and after the current time to compensate.

Using the wrong hash algorithm is another pitfall. While SHA-1 remains the default for most services, some modern systems require SHA-256 or SHA-512. Always check the provisioning URI or documentation. Finally, never paste a live production secret into any online tool. Although this totp generator processes everything locally in your browser, copying secrets carelessly increases exposure risk.

Base32 encoding and secret formatting

TOTP secrets are typically shared as Base32 strings because they avoid visually ambiguous characters found in Base64, such as 0 vs O or 1 vs l. The alphabet consists of A-Z and 2-7. Padding with = is optional and usually omitted in authenticator URIs.

This tool strips spaces and padding automatically, so you can paste formatted secrets directly. Under the hood, the Base32 string is decoded into raw bytes, which become the key for the HMAC function. If the input contains characters outside the Base32 alphabet, the totp generator returns an error rather than producing an incorrect code silently.

Worked examples

ExampleInputResult
RFC 6238 SHA-1 test vector (time 59)Base32 secret: GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ; Digits: 8; Period (seconds): 30; Algorithm: SHA1; Unix time (optional): 59Current code: 94287082; Seconds remaining: 1; Next code: 37359152; Time step (counter): 1
Standard 6-digit authenticator appBase32 secret: JBSWY3DPEHPK3PXP; Digits: 6; Period (seconds): 30; Algorithm: SHA1Current code: 404009; Seconds remaining: 9; Next code: 448045; Time step (counter): 59797585
RFC 6238 SHA-256 test vectorBase32 secret: GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQGEZA; Digits: 8; Period (seconds): 30; Algorithm: SHA256; Unix time (optional): 59Current code: 46119246; Seconds remaining: 1; Next code: 30882438; Time step (counter): 1
RFC 6238 SHA-512 test vectorBase32 secret: GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQGEZDGNA; Digits: 8; Period (seconds): 30; Algorithm: SHA512; Unix time (optional): 59Current code: 90693936; Seconds remaining: 1; Next code: 68765371; Time step (counter): 1

FAQ

What is a TOTP generator?

A TOTP generator computes Time-based One-Time Passwords from a shared Base32 secret and the current Unix time. It follows the algorithm specified in RFC 6238, which is the standard behind most authenticator apps.

Can I use this as an HOTP calculator?

Yes. Set the period to 1 and enter the desired counter value as the Unix time. For example, time 0 with a period of 1 computes the HOTP value for counter 0, yielding 755224 for the standard RFC 4226 test secret.

Why does my code not match my authenticator app?

Check that the secret, digit count, period and algorithm all match exactly. Clock skew between your device and the server can also cause mismatches. Use the Unix time override field to test specific moments.

Is it safe to enter my secret here?

This totp generator runs entirely in your browser. No data is sent over the network. However, you should never paste live production secrets into any tool as a general security practice.

Which hash algorithms are supported?

SHA-1, SHA-256 and SHA-512 are supported. SHA-1 is the default and most widely used, but some services require SHA-256 or SHA-512 for stronger cryptographic guarantees.

How do I decode a Base32 secret?

You do not need to decode it manually. Paste the Base32 string directly into the secret field. The tool decodes it internally into the raw bytes required for the HMAC computation.