On this page
hashlib.sha1
Prev: hashlib.pbkdf2_hmac | Up: hashlib | Next: hashlib.sha224
Rel: hashlib.blake2b, hashlib.blake2s, hashlib.file_digest, hashlib.md5
Ref: docs.python.org — hashlib.sha1
Tags: #public #python3 #stdlib #hashlib
Import
import hashlib
from hashlib import sha1
Signature & Overview
hashlib.sha1(data=b'', *, usedforsecurity=True, string=None)
Returns a sha1 hash object; optionally initialized with a string
Usage
import hashlib
h = hashlib.sha1(b"blob", usedforsecurity=False).hexdigest()
assert len(h) == 40
Gotchas
- Collision-broken for security: Use SHA-1 only for legacy protocol/VCS compatibility (passing
usedforsecurity=False), never for new security designs.
REPL Inspect
from hashlib import sha1
help(sha1)
Linked from
Related notes
- tuts/python3/stdlib_module/hashlib/pbkdf2_hmac Linked here; links to this page; shared tags: #hashlib, #stdlib
- tuts/python3/stdlib_module/hashlib/sha224 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/sha256 shared tags: #hashlib, #stdlib
- tuts/python3/stdlib_module/hashlib/sha384 shared tags: #hashlib, #stdlib