Hash a String (MD5, SHA256)

Compute MD5 or SHA256 hash of a string.

Code

Python
import hashlib

text = "hello"
md5_hash = hashlib.md5(text.encode()).hexdigest()
sha256_hash = hashlib.sha256(text.encode()).hexdigest()

print("MD5:", md5_hash)
print("SHA256:", sha256_hash)

Line-by-line explanation

Expected output

MD5: 5d41402abc4b2a76b9719d911017c592
SHA256: 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824

Related snippets

Related DuskTools