ハッシュ/暗号
Bcrypt Hash + Verify
bcryptでパスワードをハッシュ化(ランダムなソルトと調整可能なコスト)し、既存のbcryptハッシュに対してパスワードを検証。
Bcrypt is a deliberately slow password-hashing algorithm: unlike MD5 or SHA-256, it intentionally requires heavy computation so that brute-forcing passwords stays impractical even if a database of hashes leaks.
How to use it
- Hash: enter a password and set a cost factor — a higher number means slower, more secure hashing.
- Every hash call generates a fresh random salt, so the same password produces a different hash each time — that's expected and normal.
- Verify: paste a password and an existing bcrypt hash to check whether they match, without hashing manually yourself.
Common uses
- Manually checking that a backend hashes passwords correctly before storing them.
- Generating a test bcrypt hash for seed data or fixtures during development.
- Debugging a failed login by comparing an entered password against the stored hash.
Things to keep in mind
Pick a cost factor that keeps hashing around 100-300ms on your target server — a balance between security and login-time load.
Bcrypt truncates passwords longer than 72 bytes — characters beyond that limit are ignored by the algorithm.
よくある質問
bcryptに「コスト」や「ラウンド数」係数があるのはなぜですか?
コスト係数は内部でハッシュ処理を何回繰り返すかを制御し、値が大きくなるほどハッシュ処理は指数関数的に遅くなります。これにより、ハードウェアが高速化しても総当たり攻撃に耐えられるよう、意図的に十分遅く保つことができます。
パスワードに関係なくbcryptハッシュが常に同じ長さなのはなぜですか?
Bcryptはアルゴリズムのバージョン、コスト係数、ソルト、ハッシュをまとめてエンコードした固定長のハッシュ(通常60文字)を出力します。長さは元のパスワードの長さに依存しません。
bcryptには別途ソルトのフィールドが必要ですか?
いいえ。ソルトは自動生成され、出力文字列に直接埋め込まれるため、別途保存・管理する必要はありません。パスワードをハッシュと照合するたびに含まれています。
bcryptにはパスワードの長さの制限がありますか?
はい、bcryptはパスワードの最初の72バイトしか処理しません——それを超える部分は警告なく単に切り捨てられます。実際にはこれが問題になることはめったにありませんが、非常に長いパスワードや、1文字が複数バイトを占めることがある非ASCII文字を扱う際には覚えておく価値があります。
Argon2があるのに、なぜbcryptがまだ推奨されるのですか?
Bcryptは数十年にわたって実際に使われてきた実績があり、あらゆる言語やフレームワークで広くサポートされており、依然として十分に信頼できる選択肢です。Argon2はGPU/ASICを使った攻撃への耐性から新規システムでは優先的に推奨されますが、bcryptが危険とみなされているわけではなく、専用ハードウェアへの耐性がやや劣るだけです。