TOTP Generator
Generate time-based one-time passwords.Runs in this tab.⌘ ↵ runs it
Next step
Turn a click-through into an interactive demo
AtriumKit records your web app once in Chrome and turns every click into a step of a demo you can embed or share. There’s a free plan.
Try AtriumKit freeAbout TOTP Generator
What the generator computes
TOTP (RFC 6238) is HOTP (RFC 4226) with a counter that comes from the clock. For each code, the tool:
- Decodes the Base32 secret into raw key bytes.
- Computes the counter, the Unix time divided by the period and rounded down, as an 8-byte big-endian integer.
- Computes the HMAC of the counter with the key, using SHA-1, SHA-256 or SHA-512 as selected, through the browser’s Web Crypto API.
- Truncates the result: the low 4 bits of the last HMAC byte give an offset. The tool reads the 4 bytes at that offset, clears the top bit, and takes the result mod 10^digits, zero-padded. The offset is at most 15 whatever the hash, so with SHA-256 (32 bytes) and SHA-512 (64 bytes) the code still comes from the first 19 bytes.
Here’s the RFC 6238 test secret, the ASCII string 12345678901234567890, at Unix time 59:
secret GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ
counter floor(59 / 30) = 1 → 00 00 00 00 00 00 00 01
HMAC 75a48a19d4cbe100644e8ac1397eea747a2d33ab
offset last byte 0xab → low 4 bits 0xb = 11
4 bytes c1397eea → top bit cleared → 0x41397eea = 1094287082
code 1094287082 mod 10^8 = 94287082 (6 digits: 287082)
Settings and limits
| Parameter | Standard default | This tool |
|---|---|---|
| Hash | HMAC-SHA-1 (RFC 6238 also allows SHA-256 and SHA-512) | SHA-1, SHA-256 or SHA-512 |
| Digits | 6 | 6 or 8 |
| Period | 30 seconds | 30 or 60 seconds |
| Start time (T0) | 0, the Unix epoch | 0 |
| Secret length | At least 128 bits, 160 recommended (RFC 4226) | Any non-empty length |
If a service’s setup URI says algorithm=SHA256 or SHA512, pick the same algorithm, or paste the whole URI and the tool sets it for you. A period other than 30 or 60 seconds, or a code length other than 6 or 8 digits, isn’t supported; use pyotp for those (see below).
How the secret field reads input:
- Case and spacing don’t matter. Spaces and
=padding are stripped, sojbsw y3dp ehpk 3pxpworks. - Only A–Z and 2–7 are valid. A
0,1,8,9or hyphen gets the error “Invalid Base32 character”. That usually means an O or I was copied as a digit, or that the secret is in hex. - A whole otpauth://totp/ URI works too. The tool reads the secret, algorithm, digits and period from it, replaces the field with the Base32 secret, and shows the issuer and account name under the field. Percent-encoding (
%20,%3D), lowercase, spaces and missing padding in the secret are all handled. Parameters the URI leaves out get the format’s defaults: SHA1, 6 digits, 30 seconds. - Some URIs are rejected with a message:
otpauth://hotp/(HOTP codes come from a counter, not the clock), a URI without asecret, anddigitsorperiodvalues the tool can’t produce. - Each character carries 5 bits. 16 characters is 80 bits, 26 is about 128 and 32 is 160.
To convert a hex secret, run this, which prints the test secret above:
python3 -c "import base64; print(base64.b32encode(bytes.fromhex('3132333435363738393031323334353637383930')).decode())"
The otpauth:// URI
When you enable 2FA, the QR code a service shows you contains a URI like this:
otpauth://totp/Example:alice@example.com?secret=JBSWY3DPEHPK3PXP&issuer=Example&algorithm=SHA1&digits=6&period=30
| Part | Meaning |
|---|---|
totp |
The type. hotp URIs carry a counter parameter instead |
Example:alice@example.com |
The label, made of issuer and account name, URL-encoded |
secret |
Base32 secret with padding omitted. The only required parameter |
issuer |
The service name, which should match the label prefix |
algorithm |
SHA1 (default), SHA256 or SHA512 |
digits |
6 (default) or 8 |
period |
Seconds per code, default 30 |
Authenticator apps differ in which non-default values they honor, which is why most services stick with SHA-1, 6 digits and 30 seconds. To load a secret into an app, paste a URI like the one above into the QR code generator and scan it. To check what an app will show, paste the same URI into this tool. Google Authenticator’s export codes (otpauth-migration://offline?data=…) use a different format: a Base64 protobuf bundle of several accounts with secrets stored as raw bytes. The tool recognizes them and asks for a single otpauth://totp/ URI or Base32 secret instead.
Clock drift
Codes are computed from Unix time, which is the same in every time zone, so only your clock’s accuracy matters. With a 30-second period the code changes at :00 and :30 past each minute. With 60 seconds it changes on the minute.
The tool reads your device clock, shows only the current code, and has no offset setting. If your clock runs 10 seconds fast, then for the last 10 seconds of each window you’re seeing the code the server expects next. RFC 6238 recommends that servers allow at most one extra time step for network delay, and many verifiers accept the codes just before and after the current one. A clock a few seconds off still works, but one that’s off by more than a full period doesn’t. To check yours:
sntp time.apple.com # macOS: prints your clock's offset in seconds
timedatectl # Linux: look for "System clock synchronized: yes"
Checking codes in your own code
import hashlib, pyotp # pip install pyotp
totp = pyotp.TOTP('JBSWY3DPEHPK3PXP') # SHA-1, 6 digits, 30 s: the tool's defaults
totp.now() # the code this page shows right now
totp.verify(code, valid_window=1) # also accept the previous and next code
pyotp.TOTP(secret, digest=hashlib.sha256).now() # for algorithm=SHA256 accounts
On the command line, oathtool --totp -b JBSWY3DPEHPK3PXP prints the current code, and --totp=SHA256 or --totp=SHA512 switches the hash. To test an implementation, check it against the RFC 6238 test vectors (8 digits, 30-second period). Each hash has its own seed: the ASCII digits 1234567890 repeated to 20 bytes for SHA-1, 32 bytes for SHA-256 and 64 bytes for SHA-512. In Base32:
SHA-1 GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ
SHA-256 GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQGEZA
SHA-512 GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQGEZDGNA
| Unix time | UTC | SHA-1 | SHA-256 | SHA-512 |
|---|---|---|---|---|
| 59 | 1970-01-01 00:00:59 | 94287082 | 46119246 | 90693936 |
| 1111111109 | 2005-03-18 01:58:29 | 07081804 | 68084774 | 25091201 |
| 1111111111 | 2005-03-18 01:58:31 | 14050471 | 67062674 | 99943326 |
| 1234567890 | 2009-02-13 23:31:30 | 89005924 | 91819424 | 93441116 |
| 2000000000 | 2033-05-18 03:33:20 | 69279037 | 90698825 | 38618901 |
| 20000000000 | 2603-10-11 11:33:20 | 65353130 | 77737706 | 47863826 |
The RFC’s Appendix B text names only the 20-byte seed, but its reference code and the published SHA-256 and SHA-512 codes use the longer ones, so an implementation that reuses the 20-byte key fails those rows. The last time is beyond 2^32 seconds, so it catches code that stores Unix time in 32 bits. The 07081804 row checks that leading zeros are kept. This tool matches all 18 codes.
Questions
What is TOTP?
Is this secure to use online?
Why does my TOTP code not match the authenticator app?
What is the difference between TOTP and HOTP?
Can I use this TOTP tool to test my 2FA implementation?
How do I extract a TOTP secret from a QR code?
Comments
More in Hashing & Crypto
- UUID Generator
- Hash Generator
- Password Generator
- Bcrypt Generator
- HMAC Generator
- Checksum Calculator
- MD5 Hash Generator
- SHA-256 Hash Generator
Comments