सामग्री पर जाएँ
HexaTransfer
ब्लॉग पर वापस
एन्क्रिप्शन और सुरक्षा

हैश फ़ंक्शन समझाया: फ़ाइल इंटीग्रिटी सरलता से जांचें

ट्रांसफर के बाद फ़ाइल इंटीग्रिटी की जांच के लिए हैश फ़ंक्शन ज़रूरी हैं। SHA-256 और MD5 कैसे फ़ाइलें अपरिवर्तित सुनिश्चित करते हैं।

एक hash function किसी भी input लेता है और fixed-size output produce करता है — SHA-256 हमेशा exactly 256 bits (32 bytes) produce करता है, चाहे input एक tweet हो या 10 GB वीडियो। Input का एक bit बदलें, और लगभग आधे output bits flip हो जाते हैं। यह one-way, deterministic property hashes को file integrity verify करने का default tool बनाती है: भेजने से पहले SHA-256(file) compute करें, receive करने के बाद फिर compute करें — अगर hashes match करें तो फ़ाइल intact पहुँची। इसी से Linux distributions ISO downloads verify करती हैं, Git commits identify करता है, और HexaTransfer जैसी services multi-gigabyte uploads corruption के बिना complete होने की confirm करती हैं।

Hash function क्या guarantee करता है

तीन properties एक cryptographic hash function define करती हैं:

  • Deterministic. Same input हमेशा same output produce करता है। SHA-256("hello") हमेशा 2cf24dba5fb0a30e... है।
  • Pre-image resistance. एक hash दिया जाए, आप efficiently ऐसा input नहीं ढूंढ सकते जो उसे produce करे।
  • Collision resistance. आप efficiently दो अलग inputs नहीं ढूंढ सकते जो same hash produce करें।

साथ में दो useful behaviors:

  • Avalanche effect. एक input bit बदलने से लगभग 50% output bits flip होते हैं। Hashes को searching के लिए बेकार और fingerprinting के लिए excellent बनाता है।
  • Fixed output size. SHA-256 32 bytes है, SHA-512 64 bytes है, BLAKE2b 64 bytes है, input size से independent।

Hashes encryption नहीं हैं। वे one-way हैं — आप output से input recover नहीं कर सकते। यही तो point है।

SHA family

Secure Hash Algorithm family, NIST द्वारा FIPS 180-4 और FIPS 202 में standardized:

  • SHA-1 — 160 bits, 2017 में Google के SHAttered attack से broken। Security के लिए use न करें।
  • SHA-2 (SHA-224, SHA-256, SHA-384, SHA-512). Modern systems की workhorse। SHA-256 dominant है।
  • SHA-3 (Keccak). Different construction (sponge, Merkle-Damgård नहीं), 2015 में SHA-2 weaknesses के खिलाफ hedge के रूप में standardized — जो वास्तव में materialize नहीं हुईं।

SHA-256 वह है जो TLS certificates sign करती हैं, Bitcoin mine करता है, Git use करता है, और file transfer services integrity checks के लिए compute करती हैं। Modern CPUs पर SHA extensions के साथ throughput: 2–4 GB/s per core।

MD5 और SHA-1 security के लिए dead क्यों हैं

MD5 (1991) 128-bit hashes produce करता है और 2004 तक standard था जब collisions demonstrate हुए। 2012 तक, Flame malware ने MD5 collision attack से Microsoft code-signing certificates forge किए। अब आप laptop पर सेकंडों में MD5 collisions generate कर सकते हैं।

SHA-1 लंबे समय तक चला लेकिन 2017 में Google के SHAttered attack से गिरा, जिसने identical SHA-1 hashes वाले दो PDFs produce किए — 110 GPU-years के compute के बाद, अब cloud GPUs पर $100,000 से कम में reproducible।

दोनों non-security uses के लिए ठीक हैं: accidental corruption detect करना, storage deduplicate करना, cache keys fingerprint करना। वे digital signatures, password verification, या जहाँ attacker match forge करने से benefit करे, के लिए ठीक नहीं हैं।

BLAKE2 और BLAKE3: speed meets security

BLAKE2 (2012) और BLAKE3 (2020) SHA-3-level security SHA-256 की 2–10x speed पर offer करते हैं। BLAKE3 single-threaded लगभग 6 GB/s hit करता है और cores पर linearly parallelize होता है — एक 16-core machine 100+ GB/s hit कर सकती है।

Adoption बढ़ रही है: WireGuard authentication के लिए BLAKE2s use करता है, Zcash BLAKE2b use करता है, और developer tooling में b3sum sha256sum का common replacement बन रहा है। Multi-gigabyte uploads process करने वाली file transfer services increasingly BLAKE3 use करती हैं hash computation को bottleneck बनने से रोकने के लिए।

Browsers Web Crypto API के ज़रिये अभी BLAKE3 expose नहीं करते, इसलिए JavaScript implementations browser में लगभग 500 MB/s पर WASM-compiled reference code पर rely करती हैं।

File transfer workflows में hashes

कई जगह hashes अपना काम करते हैं:

  • Post-upload integrity check. Client upload के दौरान SHA-256 compute करता है, server arrival पर compute करता है, mismatches re-upload trigger करते हैं। S3 इसके लिए MD5 use करता है क्योंकि speed passive corruption के खिलाफ collision resistance से ज़्यादा matter करती है।
  • Chunked upload verification. बड़ी files 4 MB या 5 MB chunks में split होती हैं; प्रत्येक chunk को hash मिलता है, और hashes का एक tree (Merkle tree) पूरी file के लिए single root hash produce करता है।
  • Deduplication. अगर दो users same file upload करें, hashes match करते हैं, storage एक बार store करता है। Dropbox के block-level dedup और CDN caching द्वारा use।
  • Download verification. कुछ services download page पर SHA-256 display करती हैं ताकि recipients verify कर सकें।
  • Version identification. Git commit IDs के लिए SHA-1 use करता है (SHA-256 transition अभी progress में) — file का content उसकी identity determine करता है।

HMAC extension

Plain hashes integrity verify कर सकते हैं लेकिन authenticity नहीं — कोई भी SHA-256(file) compute कर सकता है। एक secret key जोड़ने से hash एक Message Authentication Code (MAC) बन जाता है: केवल key वाला व्यक्ति MAC produce या verify कर सकता है।

HMAC (RFC 2104) standard construction है: HMAC(key, msg) = SHA-256(key' ⊕ opad || SHA-256(key' ⊕ ipad || msg))। TLS 1.2, HS256 से signed JWTs, AWS request signing, और कई session-cookie schemes में use।

File transfer में, HMAC AES-GCM के authentication tag में appear होता है (जो GHASH use करता है, HMAC नहीं, लेकिन same role serve करता है) और कुछ services के API request signing में।

Merkle trees: scale पर hashing

बहुत बड़ी files या files के collections के लिए, हर बार पूरी चीज़ hash करना wasteful है। एक Merkle tree hashes को binary tree में arrange करता है: leaves chunk hashes हैं, internal nodes अपने children के hashes हैं, root hash पूरे data set represent करती है।

Benefits:

  • Efficient updates. एक chunk बदलने पर केवल log(n) nodes rehash होती हैं।
  • Proof of inclusion. आप prove कर सकते हैं कि एक specific chunk root का part है केवल log(n) sibling hashes से।
  • Parallel computation. Branches independently hash होती हैं।

BitTorrent (post-v2), IPFS content addressing, Git के tree objects, certificate transparency logs, और blockchain transaction roots द्वारा use। File transfer services Merkle trees resumable uploads के लिए use करती हैं जहाँ partial uploads को original के खिलाफ verify होना होता है।

Passwords और hashes

Hashes का एक application: passwords को storage-safe values में बदलना। Naive SHA-256(password) insufficient है — GPU farms प्रति सेकंड अरबों SHA-256 compute करती हैं, इसलिए कोई भी common password instantly fall होता है।

Password-specific hashes computational cost जोड़ते हैं:

  • PBKDF2-HMAC-SHA-256 600,000 iterations के साथ (OWASP 2023)।
  • bcrypt cost factor 12 के साथ (प्रति hash लगभग 250 ms)।
  • scrypt GPUs resist करने के लिए memory hardness के साथ।
  • Argon2id — वर्तमान best practice, memory-hard और parallel-resistant।

Goal hash के ज़रिये security नहीं है — यह हर guess को इतना expensive बनाना है कि weak passwords को छोड़कर offline brute force impractical हो जाए।

Download को manually verify करना

कोई भी file जो matter करती है उसे command-line tools से verify किया जा सकता है। macOS या Linux पर:

shasum -a 256 ubuntu-24.04.iso

Windows PowerShell पर:

Get-FileHash ubuntu-24.04.iso -Algorithm SHA256

Output को ubuntu.com पर published hash से compare करें। अगर match करें, तो file intact download हुई और Canonical ने जो sign किया उससे match करती है। अगर differ करें, तो download corrupt हुई या किसी ने file swap की।

Maximum trust के लिए, GPG और Canonical की signing key से hash file पर signature verify करें। Multi-step chain — signed hash file → file hash → file — Linux distributions ने दशकों से trust maintain करने का तरीका है।

Transfer service का integrity handling check करना

किसी भी file transfer provider से पूछने लायक चार सवाल:

  • Uploads verify करने के लिए आप कौन सा hash algorithm use करते हैं? (SHA-256 या BLAKE3 ठीक हैं; MD5 केवल corruption checks के लिए tolerable है; silence yellow flag है।)
  • क्या आप recipient को hash surface करते हैं? (सभी नहीं करते, लेकिन nice है।)
  • Chunked uploads के लिए, क्या आप Merkle-tree verify करते हैं?
  • क्या endpoints पर hashes compare करने का कोई तरीका है?

SwissTransfer, Tresorit, Proton Drive, और HexaTransfer सभी transfer के दौरान SHA-256 compute करते हैं और arrival पर verify करते हैं। Integrity failures पूरे transfer को fail करने की बजाय affected chunks के automatic re-upload trigger करते हैं।

इसे काम में लगाएं

अपने अगले sensitive transfer के लिए: upload से पहले shasum -a 256 file.pdf run करें, hash save करें, और download के बाद recipient को भी यही करने दें। Matching hashes byte-for-byte integrity prove करती हैं। यह 30 seconds का काम है जो corruption, tampering, और occasional misconfigured CDN catch करता है।

hexatransfer.com पर आज़माएं — मुफ्त, बिना अकाउंट, 10 GB तक।

एंड-टू-एंड एन्क्रिप्शन के साथ बड़ी फ़ाइलें सुरक्षित रूप से भेजें

एंड-टू-एंड एन्क्रिप्शन के साथ 10 GB तक की फ़ाइलें मुफ़्त में ट्रांसफ़र करें। अकाउंट की आवश्यकता नहीं। अपलोड से पहले आपकी फ़ाइलें ब्राउज़र में एन्क्रिप्ट की जाती हैं — कोई और उन्हें पढ़ नहीं सकता।

फ़ाइल भेजें