ハッシュ/暗号
TOTP Generator/Verifier
時間ベースのワンタイムパスワード(TOTP、RFC 6238) — シークレットから現在のコードを生成し、時刻のずれを許容しつつ入力されたコードを検証。
------
TOTP (Time-based One-Time Password, RFC 6238) is a two-factor authentication algorithm that generates a one-time code from a secret and the current time. It's exactly what runs under the hood in Google Authenticator, Authy, and similar apps.
How to use it
- Generate: paste a secret key (usually Base32, the same one encoded in a 2FA setup QR code) and the tool shows the current 6-digit code along with the time left before it changes.
- Verify: enter a secret and a code from an authenticator app to check whether they match.
- Verification tolerates a small amount of clock drift — it accepts a code from a neighboring time step, not just the current one.
Common uses
- Debugging your own 2FA implementation on the backend — checking that the server generates and accepts codes correctly.
- Manually generating a code for an account when you don't have your phone with the authenticator app handy.
- Figuring out why an app's code is being rejected by the server (usually the cause is a clock out of sync).
Things to keep in mind
A TOTP code is only valid for a short window (usually 30 seconds) — that time limit is the main protection, not the secret alone.
Code accuracy depends directly on the device's clock being synced; a noticeable clock drift is the most common cause of rejected 2FA codes.
よくある質問
生成したコードがすぐに期限切れになるのはなぜですか?
TOTPコードは時間ベースです — デフォルトでは現在のUnix時間と共有シークレットから計算され、30秒ごとに切り替わります。この短いウィンドウが、漏洩したコードが有効なままである時間を制限します。
デバイスの時計がずれているとどうなりますか?
TOTPは両者が現在時刻についておおよそ一致していることに依存します。ほとんどの認証アプリとサーバーは小さな時刻のずれ(通常1タイムステップ)を許容しますが、それ以上のずれがあると有効なコードが拒否されます。
ここでコードを生成する際、秘密鍵はどこかに送信されますか?
いいえ。TOTPコードはブラウザ内で完全に計算されます — 秘密鍵はデバイスから外に出ることはありません。
TOTPはフィッシングから守ってくれますか?
完全には守れません。被害者が偽サイトにパスワードと現在のTOTPコードを入力すると、攻撃者はそのコードがまだ有効なうちに両方の値を本物のサイトで即座に使うことができます。このようなリアルタイムの攻撃から守れるのは、FIDO2/WebAuthn規格のハードウェアキーだけです。
なぜサーバーは現在の時間間隔だけでなく、直前の時間間隔も受け入れるのですか?
これは、電話でコードが生成されてからサーバーがそれを受け取り検証するまでのわずかなネットワーク遅延を補うためです。この許容がなければ、数秒程度の通常の遅延で正当なコードが拒否されてしまうことがあります。