all Python 3hashlibfunction
hashlib.sha224()
hashing
The SHA-224 hash from the SHA-2 family: 28 bytes, 56 hex digits. Use it when a format demands it; the default choice is sha256().
Syntax
hashlib.sha224(data=b'', *, usedforsecurity=True)
SHA-224 is not a truncated SHA-256 of the same input: it starts from different initial constants, so sha256().hexdigest()[:56] is a completely different value, and you cannot cut a sha256 digest instead of computing sha224. The speed is the same — the compression function is shared — so the only gain is a shorter result.
Examples
import hashlib
h = hashlib.sha224(b'abc')
print(h.hexdigest()[:16], len(h.hexdigest())) # → 23097d223405d822 56
import hashlib
a = hashlib.sha224(b'abc').hexdigest()
b = hashlib.sha256(b'abc').hexdigest()[:56]
print(a == b) # → False — разные начальные константы
See also
Open in the full glossarydocs.python.orgReport an inaccuracy