On this page
hashlib.new
Prev: hashlib.md5 | Up: hashlib | Next: hashlib.pbkdf2_hmac
Rel: hashlib.blake2b, hashlib.blake2s, hashlib.file_digest, hashlib.md5
Ref: docs.python.org — hashlib.new
Tags: #public #python3 #stdlib #hashlib
Import
import hashlib
from hashlib import new
Signature & Overview
hashlib.new(name, *args, **kwargs)
optionally initialized with data (which must be a bytes-like object).
Usage
import hashlib
h = hashlib.new("sha256", b"payload")
assert h.hexdigest() == hashlib.sha256(b"payload").hexdigest()
Gotchas
- Useful when the algorithm name is dynamic: For fixed algorithms, calling
hashlib.sha256(...)directly is slightly faster thanhashlib.new("sha256", ...). - Unknown algorithm raises
ValueError: Checkhashlib.algorithms_availablefirst if accepting user input.
REPL Inspect
from hashlib import new
help(new)
Linked from
Related notes
- tuts/python3/stdlib_module/hashlib/blake2b Linked here; links to this page; shared tags: #hashlib, #stdlib
- tuts/python3/stdlib_module/hashlib/blake2s Linked here; links to this page; shared tags: #hashlib, #stdlib
- tuts/python3/stdlib_module/hashlib/file_digest Linked here; links to this page; shared tags: #hashlib, #stdlib
- tuts/python3/stdlib_module/hashlib/md5 Linked here; links to this page; shared tags: #hashlib, #stdlib
- tuts/python3/stdlib_module/hashlib/pbkdf2_hmac 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/sha1 shared tags: #hashlib, #stdlib
- tuts/python3/stdlib_module/hashlib/sha224 shared tags: #hashlib, #stdlib
- tuts/python3/stdlib_module/hashlib/sha256 shared tags: #hashlib, #stdlib
- tuts/python3/stdlib_module/hashlib/sha384 shared tags: #hashlib, #stdlib