TOTP Generator
Turn a Base32 secret into the same 6-digit code as your phone authenticator, computed offline in JavaScript with HOTP, code lookup and clock drift checks
只在本地算,密钥不外传
本页 100% 离线:所有 SHA-1 / HMAC-SHA1 / Base32 计算都是页面内的纯 JS 代码, 不发任何网络请求(连字体和图片都不从 CDN 取),断网、内网 http 打开照样能用。
账户只存在这台浏览器的 localStorage(键名 u2-totp-accounts)里, 不上传、不进任何统计;换浏览器或清掉站点数据就没了,请自行在验证器里留一份。
本页 100% 离线:所有 SHA-1 / HMAC-SHA1 / Base32 计算都是页面内的纯 JS 代码, 不发任何网络请求(连字体和图片都不从 CDN 取),断网、内网 http 打开照样能用。
账户只存在这台浏览器的 localStorage(键名 u2-totp-accounts)里, 不上传、不进任何统计;换浏览器或清掉站点数据就没了,请自行在验证器里留一份。
当前时间因子
Unix 秒—
计数值 counter—
倒计时—
计时用 Date.now() 的绝对时间戳现算,不是每秒累加:切到别的标签页、电脑休眠再回来,
口令和进度条都会直接对齐真实时间,不会越计越偏。周期切换取上方表单里的「周期」。
我的账户
口令默认打码(只露最后 3 位),点大号口令那行临时显示完整口令 10 秒后自动遮回;
点卡片空白处直接复制当前口令。上面一排按钮分别是编辑、复制 otpauth 链接、看链接原文、上移、下移、删除(删除要连点两次确认)。
新增账户
固定 HMAC-SHA1(纯 JS 实现,不用 crypto.subtle,内网 http 打开也能算)。
主流验证器(Google Authenticator / 微软 Authenticator / 1Password / FreeOTP)默认都是 SHA-1,
所以绑定时看到 SHA-256、SHA-512 的选项请保持默认;真遇上非 SHA-1 的站点,本页导入时会提醒你口令可能对不上。
从验证器导入 / 导出 otpauth 链接
本页不生成二维码(不引任何第三方二维码库):手机验证器都有「输入一个设置密钥 / 粘贴 otpauth 链接」的入口,
把上面这条链接复制过去粘贴即可,比拍照扫码更不容易出错。手动录入时要填的是去掉空格的大写 Base32 密钥,
位数和周期如果改过也要一起在验证器里改,否则两边算出来的口令不一样。
与 RFC 6238 / RFC 4226 官方向量对照
| 类型 | 输入 | RFC 期望值 | 本页算出 |
|---|
测试密钥是 RFC 6238 附录 B 的 ASCII 串 12345678901234567890,Base32 写法
GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ(8 位口令、周期 30 秒)。
这个密钥是公开印在标准里的,不要拿去绑真实账号,只用来验证算法实现对不对。
想核对真实账号时,把「载入 RFC 6238 示例密钥」生成的那个示例账户删掉即可。
About this tool
The six digits in two-factor authentication are not random and do not come from the server. They are computed from the secret stored on your phone plus the current time, so any device holding the same secret and parameters produces the same code in the same second. This tool runs the formula in your browser: enter the secret and the code matches your phone authenticator.
How the code is computed
- Shared secret: the Base32 string from enrollment, such as
JBSWY3DPEHPK3PXP, stored once by the site and once on your device - Time factor: Unix seconds divided by the period, 30 by default and rounded down, giving a counter that increments every 30 seconds
- HMAC-SHA1: key the secret with that 8-byte big-endian counter to get a 20-byte digest
- Dynamic truncation: take the low 4 bits of the last digest byte as an offset, read 4 bytes from there and clear the top bit for a 31-bit integer
- Modulo: reduce modulo
10^digits, so six digits meansmod 1000000, padded with leading zeros - The server does the same: it recomputes with its own clock and usually accepts one period before or after to absorb clock differences
What the page does
- TOTP codes: multiple account cards, codes masked except the last three digits, tap to reveal for 10 seconds, tap the card to copy
- Time factor panel: live Unix seconds, current counter and remaining seconds with a ring and bar that reset each period. Timing is computed from the absolute timestamp rather than accumulated ticks, so switching tabs or waking from sleep stays aligned
- HOTP counter: enter a counter to generate a code, increment and remember it to simulate an event-based token, or list 10 consecutive codes to check RFC 4226 appendix D
- Code lookup: paste the six digits shown on your phone and search one or two periods before and after across accounts. A hit in the previous period means your computer clock is fast, the next period means slow, and no hit usually means a different secret
- otpauth links: paste
otpauth://totp/...to add an account, or export an account link to your phone; parsing URL-decodes automatically, tolerates surrounding text and warns about non-SHA-1 parameters - Random secrets: 16, 20 or 32 characters (80, 128 or 160 bit) from
crypto.getRandomValues, useful when building your own site - Standard vectors: built-in RFC 6238 appendix B and RFC 4226 tables compare this page against expected values row by row
- Local accounts: stored in
localStoragewith edit, reorder, confirm-to-delete and clear-all support
Parameter reference
| Parameter | Common value | If wrong |
|---|---|---|
| secret | Base32, A to Z and 2 to 7 | One wrong character produces a completely different code |
| digits | 6, occasionally 8 | Different modulo gives visibly different codes |
| period | 30 seconds, sometimes 60 | Wrong period count shifts the code by a full step |
| algorithm | SHA-1, SHA-256 or SHA-512 | Mainstream authenticators default to SHA-1 and will not match others |
| device clock | Within 30 seconds of UTC | Drift beyond one period starts producing invalid code errors |
Common questions
- Why does my code differ from the phone? Check four things in order: a copied or missed secret character (Base32 has no 0, 1, 8 or 9, and O read as 0 is common), mismatched digits or period, a drifting clock, and whether the site uses a non-SHA-1 algorithm. Code lookup here separates the first three
- Why Base32 rather than Base64? Secrets get copied by hand or read aloud, so Base32 uses 32 unconfusing uppercase letters and digits, drops look-alikes such as
0O1ILand avoids escaped+ / =characters. Spaces, hyphens, line breaks and=padding are normalized before decoding, and invalid characters are reported with their position - Can it replace a phone authenticator? It computes codes but has no system notifications, encrypted storage or multi-device sync, and clearing browser data loses accounts. Treat it as a debugging and emergency backup while keeping your main authenticator and an offline copy of the secret
- Is the secret uploaded? No. SHA-1, HMAC-SHA1 and Base32 are implemented in page JavaScript, not
crypto.subtle, and no requests are sent; it works offline or on a plain http intranet page, and accounts stay in this browser - How do I back up accounts? Copy each otpauth link into a password manager note, or export links and store them safely. The secret is plain text, so protect it like a password
- Is TOTP better than SMS? Codes are generated locally and do not depend on a carrier, so SIM swaps, SMS interception and signal coverage do not matter. The tradeoff is that a lost secret cannot be recovered by identity checks, so keep recovery codes
- Can repeated wrong codes lock me out? Lockout is server side and unrelated to this page. If codes get worse over time, check the clock first, then confirm the account is not HOTP used as TOTP
- Is HOTP still used? Hardware tokens and some legacy systems use it. It increments a counter on each use, so both sides must stay in sync and must be re-paired when they drift, which is why time-based systems use TOTP
- Can the RFC 6238 sample secret be used on a real account? No. The test secret
12345678901234567890, Base32GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ, is published in the standard, so anyone can compute its codes; it only verifies an implementation
All computation runs locally in the browser and the secret is never uploaded.