Python Glossary Русский

all Python 3hashlibfunction

hashlib.sha512()

hashing

The SHA-512 hash from the SHA-2 family: 64 bytes, 128 hex digits. The longest SHA-2 hash, computed on 64-bit words.

Syntax

hashlib.sha512(data=b'', *, usedforsecurity=True)

Longer does not mean slower: on a 64-bit CPU without hardware SHA instructions sha512() often beats sha256() on large files because it processes 128-byte blocks at a time. It is just as unfit for passwords as sha256(): a fast hash falls to a dictionary attack, use pbkdf2_hmac() with a salt. A chain of update() calls gives the same result as one call on the concatenated data.

Examples

import hashlib
h = hashlib.sha512()
h.update(b'a')
h.update(b'bc')
print(h.hexdigest()[:16])  # → ddaf35a193617aba
print(h.hexdigest() == hashlib.sha512(b'abc').hexdigest())  # → True

See also

Open in the full glossarydocs.python.orgReport an inaccuracy