Back
+15 XP
Concept

Cryptographic Hashing with hashlib

`hashlib.sha256(data).hexdigest()` produces an irreversible 64-character hexadecimal digest. Essential for data integrity and file verification 🔐.

python
import hashlib

payload = b"Immutable transaction data"
digest = hashlib.sha256(payload).hexdigest()

print(f"SHA-256: {digest} 🔐")
print(f"Length: {len(digest)} hex characters (256 bits) ✅")

# 111. Cryptographic Hashing with hashlib `hashlib.sha256(data).hexdigest()` produces an irreversible 64-character hexadecimal digest. Essential for data integrity and file verification 🔐. ```python import hashlib payload = b"Immutable transaction data" digest = hashlib.sha256(payload).hexdigest() print(f"SHA-256: {digest} 🔐") print(f"Length: {len(digest)} hex characters (256 bits) ✅") ``` Avoid deprecated algorithms like MD5 or SHA-1 for security. Use SHA-256, SHA-512, or modern BLAKE2b (`hashlib.blake2b`)! 🔐 --- ### Question How many hexadecimal characters are in a standard SHA-256 digest? 🧠 - [ ] a. 64 characters (256 bits / 4 bits per hex digit) 🔐 - [ ] b. 32 characters - [ ] c. 128 characters - [ ] d. 256 characters --- ### Challenge Import `hashlib`. Compute SHA-256 digest of `b'xicae'` using `hashlib.sha256(b'xicae').hexdigest()`. Print the digest. 🎯 <details> <summary>Solution</summary> ```python import hashlib digest = hashlib.sha256(b"xicae").hexdigest() print(digest) ``` </details>

Checkpoint

How many hexadecimal characters are in a standard SHA-256 digest? 🧠

Practice

Import `hashlib`. Compute SHA-256 digest of `b'xicae'` using `hashlib.sha256(b'xicae').hexdigest()`. Print the digest. 🎯

Terminal
01
Tap code blocks below to assemble
Available Blocks