How to hash a string with SHA-256 in Python

1 Answer

0 votes
import hashlib

def sha256(text: str) -> str:
    # Encode to bytes, compute SHA‑256, return hex string
    return hashlib.sha256(text.encode("utf-8")).hexdigest()

if __name__ == "__main__":
    input_text = "Python programming language"
    hash_value = sha256(input_text)
    print(hash_value)
    


'''
run:

da153dc6e7ded43aab6e16480018fc66fc450e7cc0fc0da1c42088b2622cf834

'''

 



answered 9 hours ago by avibootz
...