ファイルハッシュ計算
任意のファイルのMD5・SHA-1・SHA-256・SHA-512ハッシュをブラウザ内で計算します。
ファイルが選択されていません
よくある質問
コード実装
import hashlib
from pathlib import Path
def hash_file(path: str, algorithm: str = "sha256") -> str:
"""Compute the hash of a file in chunks (memory-efficient)."""
h = hashlib.new(algorithm)
with open(path, "rb") as f:
for chunk in iter(lambda: f.read(65536), b""):
h.update(chunk)
return h.hexdigest()
# Supported: md5, sha1, sha256, sha512, sha3_256, blake2b ...
file_path = "example.txt"
print("MD5: ", hash_file(file_path, "md5"))
print("SHA-1: ", hash_file(file_path, "sha1"))
print("SHA-256:", hash_file(file_path, "sha256"))
print("SHA-512:", hash_file(file_path, "sha512"))
# Hash a string directly
text = "Hello, World!"
sha256 = hashlib.sha256(text.encode()).hexdigest()
print("String SHA-256:", sha256)Comments & Feedback
Comments are powered by Giscus. Sign in with GitHub to leave a comment.