SHA-256ハッシュ生成ツール
任意のテキストからSHA-256ハッシュを生成
入力テキスト
SHA-256ハッシュ
SHA-256ハッシュがここに表示されます…
SHA-256ハッシュとは何か
SHA-256(Secure Hash Algorithm 256-bit)は、SHA-2ファミリーに属する暗号学的ハッシュ関数であり、NISTが2001年にFIPS 180-2(後にFIPS 180-4に改訂)の一部として公表しました。1文字、数ギガバイトのファイル、空文字列など、あらゆる入力に対して固定長256ビット(32バイト)のダイジェストを生成し、慣習的に64桁の16進数で表示されます。SHA-256は現在、本番システムで最も広く使われているハッシュ関数であり、TLS証明書チェーン、Bitcoinのプルーフ・オブ・ワーク、Subresource Integrity(SRI)、コード署名ワークフローなどを支えています。
SHA-256は一方向関数です。入力からハッシュを計算するのは高速(現代のハードウェアで毎秒数百メガバイト)ですが、その逆方向 — 特定のハッシュを生成する入力を見つけること — は計算上不可能です。この性質は「原像計算困難性(preimage resistance)」と呼ばれ、SHA-256をパスワードのハッシュ化(ソルトとキー・ストレッチングとの組み合わせ)、デジタル署名、データ完全性の検証に適したものにしています。MD5やSHA-1と異なり、完全なSHA-256に対する衝突攻撃や原像攻撃は実証されていません。
SHA-2ファミリーには6つの変種があります:SHA-224、SHA-256、SHA-384、SHA-512、SHA-512/224、SHA-512/256。SHA-256は32ビットワードを使用してブロックあたり64ラウンドの処理を行い、32ビットプロセッサ向けに最適化されています。SHA-512は64ビットワードと80ラウンドを使用し、64ビットプラットフォームではより高速になる場合があります。256ビットのダイジェストで十分なほとんどのアプリケーションでは、NIST・IETF・CA/Browser Forumともに引き続きSHA-256を既定の推奨として位置付けています。
オンラインSHA-256生成ツールを使う理由
SHA-256ハッシュの生成には通常、ターミナルコマンドか数行のコードが必要です。このブラウザベースのツールを使えば、何もインストールせず、コンテキストを切り替えず、スクリプトを書かずにSHA-256ダイジェストを計算できます。
SHA-256の利用シーン
SHA-2ファミリーの変種比較
SHA-256はFIPS 180-4で定義されたSHA-2ファミリーに属します。各変種はダイジェストサイズ、処理性能、セキュリティマージンのトレードオフが異なります。以下の表では、実際に目にする可能性が高いSHA-2の全変種を比較しています。
| 変種 | ダイジェストサイズ | 16進数の長さ | バイトサイズ | 主な用途 |
|---|---|---|---|---|
| SHA-256 | 256 bits | 64 hex chars | 32 bytes | TLS, blockchain, code signing, JWTs, SRI |
| SHA-224 | 224 bits | 56 hex chars | 28 bytes | Truncated SHA-256 — rare, specific compliance |
| SHA-384 | 384 bits | 96 hex chars | 48 bytes | Government / CNSS, higher collision margin |
| SHA-512 | 512 bits | 128 hex chars | 64 bytes | Digital signatures, HMAC with large keys |
| SHA-512/256 | 256 bits | 64 hex chars | 32 bytes | SHA-512 speed on 64-bit CPUs, 256-bit output |
SHA-256 対 SHA-1 対 MD5 対 SHA-3
適切なハッシュアルゴリズムの選択は、セキュリティ要件と互換性の制約によって決まります。SHA-256は実用上の最適解です。安全であり、Web Crypto APIを含めて幅広くサポートされており、ほとんどのワークロードに対して十分な速度があります。以下の比較表では、ハッシュ関数を選択する際に最も重要な特性を網羅しています。
| 特性 | SHA-256 | SHA-1 | MD5 | SHA-3-256 |
|---|---|---|---|---|
| Digest size | 256 bits (64 hex) | 160 bits (40 hex) | 128 bits (32 hex) | 256 bits (64 hex) |
| Security status | Secure | Broken (2017) | Broken (2004) | Secure |
| Collision resistance | 2^128 operations | Practical attack | Practical attack | 2^128 operations |
| Block size | 512 bits | 512 bits | 512 bits | 1600 bits (sponge) |
| Rounds | 64 | 80 | 64 | 24 |
| Standard | FIPS 180-4 | FIPS 180-4 | RFC 1321 | FIPS 202 |
| Web Crypto API | Yes | Yes | No | No |
| Primary use today | TLS, blockchain, SRI | Legacy git only | Non-security checksums | Backup standard |
SHA-256の内部動作
SHA-256はMerkle–Damgård構造を通じて、入力を512ビット(64バイト)のブロック単位で処理します。アルゴリズムは最初の8つの素数の平方根の小数部から導出された8つの32ビット状態ワード(H0〜H7)を初期化します。各ブロックはビット演算(AND、XOR、NOT、右ローテート、右シフト)と最初の64個の素数の立方根から導出された64個のラウンド定数を使った64ラウンドの混合処理を経ます。
SHA-256: b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9
(256 bits = 32 bytes = 64 hex characters)
| ステップ | 説明 |
|---|---|
| Padding | Append a 1-bit, then zeros until the message length is 448 mod 512. Append the original message length as a 64-bit big-endian integer. |
| Block splitting | Divide the padded message into 512-bit (64-byte) blocks. |
| Message schedule | Expand each 16-word (32-bit) block into 64 words using sigma functions with right-rotate and right-shift operations. |
| Compression | Process 64 rounds per block using Ch, Maj, and two Sigma functions with 64 round constants derived from cube roots of the first 64 primes. |
| Output | Concatenate the eight 32-bit state words (H0-H7) into a 256-bit (32-byte) digest, rendered as 64 hexadecimal characters. |
アバランシェ効果により、入力の1ビットを反転させると出力ビットの約50%が変化します。この性質と2^128の衝突耐性の組み合わせが、SHA-256が2026年においてもセキュリティが求められるアプリケーションの基準推奨であり続ける理由です。
SHA-256コードサンプル
SHA-256はすべての主要言語とランタイムでネイティブに利用できます。ブラウザではWeb Crypto APIがライブラリなしで提供します。以下のサンプルは、Unicode入力の処理やファイルハッシュ化を含む実践的な使用パターンを示しています。
// Works in all modern browsers and Node.js 18+
async function sha256(text) {
const data = new TextEncoder().encode(text)
const hashBuffer = await crypto.subtle.digest('SHA-256', data)
const hashArray = Array.from(new Uint8Array(hashBuffer))
return hashArray.map(b => b.toString(16).padStart(2, '0')).join('')
}
await sha256('hello world')
// → "b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9"
// Node.js (built-in crypto module)
const crypto = require('crypto')
crypto.createHash('sha256').update('hello world').digest('hex')
// → "b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9"import hashlib
# Basic SHA-256 hash
result = hashlib.sha256(b'hello world').hexdigest()
print(result) # → "b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9"
# Hash a string (encode to bytes first)
text = 'café ☕'
hashlib.sha256(text.encode('utf-8')).hexdigest()
# → "3eb53e00aa1bb4b1e8aab1ab38e56e6b8fb0b20e1cf7e1d19f36e4fad2537445"
# Hash a file in chunks (memory-efficient)
with open('release.tar.gz', 'rb') as f:
sha = hashlib.sha256()
for chunk in iter(lambda: f.read(8192), b''):
sha.update(chunk)
print(sha.hexdigest())package main
import (
"crypto/sha256"
"fmt"
)
func main() {
data := []byte("hello world")
hash := sha256.Sum256(data)
fmt.Printf("%x\n", hash)
// → b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9
}# Using sha256sum (Linux) or shasum (macOS) echo -n "hello world" | sha256sum # → b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9 - # macOS echo -n "hello world" | shasum -a 256 # → b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9 - # Verify a file checksum echo "b94d27b... myfile.bin" | sha256sum -c # → myfile.bin: OK # Using openssl (cross-platform) echo -n "hello world" | openssl dgst -sha256 # → SHA2-256(stdin)= b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9