FileDummy Logo
FileDummy
Bảo Mật & Toàn Vẹn Tệp Tin

Cách Kiểm Tra Tính Toàn Vẹn File Sau Khi Tải Xuống (Hướng Dẫn Checksum)

Xác thực tính toàn vẹn của tệp bằng MD5, SHA-256 và SHA-512 trên Windows, macOS và Linux. Các lệnh terminal thực tế và file mẫu đã băm sẵn.

17 tháng 9, 20268 phút đọc1,420 lượt xem
securitychecksummd5sha256file-integrity

Whenever you download software binaries, disk images, or confidential documents, comparing the file checksum against the publisher's published digest confirms that the file was not altered in transit or corrupted by network dropouts.

Command-Line Checksum Tools Across Platforms

Every major operating system provides built-in tools to calculate and verify hashes.

1. macOS (Terminal)

Terminal
# Compute SHA-256
shasum -a 256 sample-10mb.pdf

# Compute MD5
md5 sample-10mb.pdf

2. Linux (Ubuntu, Debian, RedHat)

Terminal
# Compute SHA-256
sha256sum sample-10mb.pdf

# Verify against a checksums.txt file
sha256sum -c checksums.txt

3. Windows (PowerShell)

POWERSHELL
# Compute SHA-256
Get-FileHash .\sample-10mb.pdf -Algorithm SHA256

# Compute MD5
Get-FileHash .\sample-10mb.pdf -Algorithm MD5
Verified Test Asset.pdf

Download our 1MB PDF sample and verify its SHA-256 checksum in your terminal right now.

Tải File Mẫu 1MB PDF →

Automating Checksum Verification in Node.js

TypeScript
import fs from 'fs';
import crypto from 'crypto';

export async function verifyDownloadedFile(
  filePath: string,
  expectedChecksum: string,
  algorithm = 'sha256'
): Promise<boolean> {
  const hash = crypto.createHash(algorithm);
  const stream = fs.createReadStream(filePath);

  for await (const chunk of stream) {
    hash.update(chunk);
  }

  const actualChecksum = hash.digest('hex').toLowerCase();
  const matches = actualChecksum === expectedChecksum.toLowerCase();

  if (!matches) {
    console.error(`Integrity mismatch! Expected: ${expectedChecksum}, got: ${actualChecksum}`);
  }

  return matches;
}

Why Verify Over HTTPS?

While TLS encrypts data in flight, a compromised content distribution network, faulty proxy cache, or interrupted connection can result in truncated or malicious payloads. Publishing SHA-256 digests out-of-band guarantees end-to-end authenticity.

NDL

Nguyễn Đại Long

Tác Giả

Backend Lead • Chuyên gia Kiến trúc Hệ thống Phân tán & Lưu trữ Đám mây

Hơn 4 năm kinh nghiệm thiết kế các hệ thống xử lý tệp tải lên thông lượng lớn, tối ưu hóa cơ sở dữ liệu và hạ tầng phân tán Cloudflare R2 / AWS S3. Người sáng lập FileDummy và Mạng lưới Hệ sinh thái NDL.

Bài viết này có hữu ích không?

Bấm Thích để ủng hộ tác giả và giúp bài viết lan tỏa tới cộng đồng lập trình viên.

Thảo Luận Kỹ Thuật & Đóng Góp Ý Kiến (0)

Chia sẻ kết quả benchmark, phản hồi các trường hợp biên hoặc đặt câu hỏi chuyên môn.

0/3000

Chưa có bình luận nào. Hãy là lập trình viên đầu tiên bắt đầu cuộc thảo luận!

Câu Hỏi Thường Gặp (FAQ)

What command verifies a SHA-256 checksum on macOS?

Run shasum -a 256 filename.pdf in Terminal. On Linux use sha256sum filename.pdf. On Windows PowerShell use Get-FileHash filename.pdf -Algorithm SHA256.

Why does my downloaded file have a different checksum?

Common causes: incomplete download, file modified in transit (rare on HTTPS), or comparing against the wrong algorithm. MD5 and SHA-256 produce completely different outputs for the same file.

Is HTTPS enough, or do I still need checksum verification?

HTTPS protects the file in transit. Checksum verification also protects against a compromised origin server serving a modified file. For security-sensitive downloads, verify checksums even over HTTPS.

Bài Viết Liên Quan