2FA コード生成 (TOTP)
Base32シークレットからTOTPの6桁ワンタイムコードを生成。
2FA コード生成 (TOTP)とは
TOTP(Time-based One-Time Password)とは、共有シークレットと現在時刻から30秒ごとに変わる6桁のコードを生成する二要素認証方式です(RFC 6238)。
🔒 処理はすべてブラウザ内で完結し、データは送信されません。
このツールの前提
- 処理場所
- このページのブラウザ内(JavaScript / Canvas)
- アップロード
- なし — ファイルは端末の外に出ません
- オフライン
- ページを開いた後は通信不要
RFC 6238, computed from a shared secret and the clock
The secret is Base32-decoded, concatenated with a counter derived from Unix time divided by the period (30 seconds by default), then HMAC-SHA1 is applied and the result is dynamically truncated to six digits. Both sides compute the same six digits from the same two inputs, which is why no network call is involved.
SHA-1 is not a weakness here. HMAC-SHA1 remains sound for this construction, and it is what every authenticator app implements — switching to SHA-256 would produce codes that Google Authenticator rejects. The algorithm is fixed by interoperability, not by preference.
Why codes are rejected when the secret is right
Clock drift is the usual cause. Servers accept the current window plus typically one before and one after, which tolerates about 90 seconds of skew. A device more than a minute off will fail intermittently, which looks like a wrong secret rather than a wrong clock.
The second cause is the secret itself. Base32 secrets are printed in four-character groups and often contain characters that look alike; dropping one group yields a shorter but structurally valid key that produces consistently wrong codes. Compare the decoded byte length against the original — 20 bytes (160 bits) is the common size.
Handling the secret
The secret is the second factor. Anyone with it can generate valid codes forever, so it deserves the same care as a password: not in screenshots, not in a ticket, not in a chat message. This page computes in the tab and transmits nothing, but the clipboard and the screen are still exposure.
If a secret may have leaked, the fix is to re-enrol the account and invalidate the old secret, not to change the password. Recovery codes are the way back in when the device is lost — store them somewhere that is not the same device.
使い方
- 1.Base32シークレットを入力
- 2.期間を確認
- 3.コードを認証画面に入力
他の方法との比較
同じ変換をする方法は 3 つあります。ブラウザ内(このページ)、サーバー側の変換サービス、デスクトップアプリ。差がつくのは速度ではなく、ファイルがどこへ行くかと、無料でどこまでできるかです。
| 観点 | このツール | サーバー側の変換サービス | デスクトップアプリ |
|---|---|---|---|
| ファイルの処理場所 | このページのブラウザ内 | ベンダーのサーバー(アップロード後) | 自分の PC(アプリをインストール) |
| アカウント | 不要 | 多くの場合必要(無料枠の制限解除に登録を求める) | 不要(ライセンス認証は必要な場合あり) |
| 無料で扱えるサイズ | サイズ制限なし(回数制限もなし) | 数ファイル/時間、または 5〜10MB 程度で課金 wall | ディスクとメモリ次第 |
| 料金 | 無料。Pro は月 $9(大きいファイルと AI 機能のみ) | サブスクが一般的。おおむね月 $7〜15(2026 年 11 月時点) | 買い切り、またはサブスク |
| オフライン | 一度開けば通信不要 | 不可 | 可 |
| 20MB を処理し始めるまで | 待ち時間なし(アップロードが無い) | アップロードが支配的(10Mbps 上りで約 16 秒) | アプリの起動のみ |
| 保証できないこと | 値は端末の CSPRNG で生成され、サーバーには送られません | 同じ(変換の原理は変わらない) | 同じ。ただし書式の再現はより忠実な場合がある |
サーバー側のサービスが優れている点は明確にあります。巨大なファイル、チームでの共有、変換履歴の管理、スクリプトからの自動化。逆に「1 回だけ、手元のファイルを別形式にしたい」という今回の用途では、アップロードの待ち時間と登録の手間だけが増えます。
よくある質問
シークレットはどこから取得しますか?
二要素認証を設定する際に表示されるBase32文字列(英大文字と数字2-7)を入力してください。
コードの有効期限は?
既定30秒です。経過すると自動的に別のコードになります。
サーバーに送信されますか?
いいえ。HMAC-SHA1の計算はブラウザ内で行います。