On this page
hashlib.sha256
Prev: hashlib.sha224 | Up: hashlib | Next: hashlib.sha384
Rel: hashlib.blake2b, hashlib.blake2s, hashlib.file_digest, hashlib.md5
Ref: docs.python.org — hashlib.sha256
Tags: #public #python3 #stdlib #hashlib
Import
import hashlib
from hashlib import sha256
Signature & Overview
hashlib.sha256(data=b'', *, usedforsecurity=True, string=None)
Returns a sha256 hash object; optionally initialized with a string
Usage
import hashlib
h = hashlib.sha256()
h.update(b"hello ")
h.update(b"world")
assert h.hexdigest() == hashlib.sha256(b"hello world").hexdigest()
assert len(h.digest()) == 32
Gotchas
- Default general-purpose cryptographic hash: Fast, widely standardized, and 256-bit (32 bytes / 64 hex chars).
- Not a password hash: Never hash user secrets with plain
sha256—usepbkdf2_hmac,scrypt, or Argon2id.
REPL Inspect
from hashlib import sha256
help(sha256)
Linked from
Related notes
- tuts/python3/stdlib_module/hashlib/sha224 Linked here; links to this page; shared tags: #hashlib, #stdlib
- tuts/python3/stdlib_module/hashlib/sha384 Linked here; links to this page; shared tags: #hashlib, #stdlib
- tuts/python3/stdlib_module/hashlib Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/hashlib/blake2b Linked here; shared tags: #hashlib, #stdlib
- tuts/python3/stdlib_module/hashlib/blake2s Linked here; shared tags: #hashlib, #stdlib
- tuts/python3/stdlib_module/hashlib/file_digest Linked here; shared tags: #hashlib, #stdlib
- tuts/python3/stdlib_module/hashlib/md5 Linked here; shared tags: #hashlib, #stdlib
- tuts/python3/stdlib_module/hashlib/new shared tags: #hashlib, #stdlib
- tuts/python3/stdlib_module/hashlib/pbkdf2_hmac shared tags: #hashlib, #stdlib
- tuts/python3/stdlib_module/hashlib/sha1 shared tags: #hashlib, #stdlib