💾 Archived View for tris.fyi › pydoc › hashlib captured on 2022-03-01 at 15:54:31. Gemini links have been rewritten to link to archived content
⬅️ Previous capture (2022-01-08)
-=-=-=-=-=-=-
hashlib module - A common interface to many hash functions. new(name, data=b'', **kwargs) - returns a new hash object implementing the given hash function; initializing the hash using the given binary data. Named constructor functions are also available, these are faster than using new(name): md5(), sha1(), sha224(), sha256(), sha384(), sha512(), blake2b(), blake2s(), sha3_224, sha3_256, sha3_384, sha3_512, shake_128, and shake_256. More algorithms may be available on your platform but the above are guaranteed to exist. See the algorithms_guaranteed and algorithms_available attributes to find out what algorithm names can be passed to new(). NOTE: If you want the adler32 or crc32 hash functions they are available in the zlib module. Choose your hash function wisely. Some have known collision weaknesses. sha384 and sha512 will be slow on 32 bit platforms. Hash objects have these methods: - update(data): Update the hash object with the bytes in data. Repeated calls are equivalent to a single call with the concatenation of all the arguments. - digest(): Return the digest of the bytes passed to the update() method so far as a bytes object. - hexdigest(): Like digest() except the digest is returned as a string of double length, containing only hexadecimal digits. - copy(): Return a copy (clone) of the hash object. This can be used to efficiently compute the digests of datas that share a common initial substring. For example, to obtain the digest of the byte string 'Nobody inspects the spammish repetition': >>> import hashlib >>> m = hashlib.md5() >>> m.update(b"Nobody inspects") >>> m.update(b" the spammish repetition") >>> m.digest() b'\xbbd\x9c\x83\xdd\x1e\xa5\xc9\xd9\xde\xc9\xa1\x8d\xf0\xff\xe9' More condensed: >>> hashlib.sha224(b"Nobody inspects the spammish repetition").hexdigest() 'a4337bc45a8fc544c03f52dc550cd6e1e87021bc896588bd79e901e2'
Return a new BLAKE2b hash object.
copy(self, /) Return a copy of the hash object.
digest(self, /) Return the digest value as a bytes object.
hexdigest(self, /) Return the digest value as a string of hexadecimal digits.
update(self, data, /) Update this hash object's state with the provided bytes-like object.
MAX_DIGEST_SIZE = 64
MAX_KEY_SIZE = 64
PERSON_SIZE = 16
SALT_SIZE = 16
block_size = <attribute 'block_size' of '_blake2.blake2b' objects>
digest_size = <attribute 'digest_size' of '_blake2.blake2b' objects>
name = <attribute 'name' of '_blake2.blake2b' objects>
Return a new BLAKE2s hash object.
copy(self, /) Return a copy of the hash object.
digest(self, /) Return the digest value as a bytes object.
hexdigest(self, /) Return the digest value as a string of hexadecimal digits.
update(self, data, /) Update this hash object's state with the provided bytes-like object.
MAX_DIGEST_SIZE = 32
MAX_KEY_SIZE = 32
PERSON_SIZE = 8
SALT_SIZE = 8
block_size = <attribute 'block_size' of '_blake2.blake2s' objects>
digest_size = <attribute 'digest_size' of '_blake2.blake2s' objects>
name = <attribute 'name' of '_blake2.blake2s' objects>
openssl_md5(string=b'', *, usedforsecurity=True) Returns a md5 hash object; optionally initialized with a string
__hash_new(name, data=b'', **kwargs) new(name, data=b'') - Return a new hashing object using the named algorithm; optionally initialized with data (which must be a bytes-like object).
pbkdf2_hmac(hash_name, password, salt, iterations, dklen=None) Password based key derivation function 2 (PKCS #5 v2.0) with HMAC as pseudorandom function.
scrypt(password, *, salt=None, n=None, r=None, p=None, maxmem=0, dklen=64) scrypt password-based key derivation function.
openssl_sha1(string=b'', *, usedforsecurity=True) Returns a sha1 hash object; optionally initialized with a string
openssl_sha224(string=b'', *, usedforsecurity=True) Returns a sha224 hash object; optionally initialized with a string
openssl_sha256(string=b'', *, usedforsecurity=True) Returns a sha256 hash object; optionally initialized with a string
openssl_sha384(string=b'', *, usedforsecurity=True) Returns a sha384 hash object; optionally initialized with a string
openssl_sha3_224(string=b'', *, usedforsecurity=True) Returns a sha3-224 hash object; optionally initialized with a string
openssl_sha3_256(string=b'', *, usedforsecurity=True) Returns a sha3-256 hash object; optionally initialized with a string
openssl_sha3_384(string=b'', *, usedforsecurity=True) Returns a sha3-384 hash object; optionally initialized with a string
openssl_sha3_512(string=b'', *, usedforsecurity=True) Returns a sha3-512 hash object; optionally initialized with a string
openssl_sha512(string=b'', *, usedforsecurity=True) Returns a sha512 hash object; optionally initialized with a string
openssl_shake_128(string=b'', *, usedforsecurity=True) Returns a shake-128 variable hash object; optionally initialized with a string
openssl_shake_256(string=b'', *, usedforsecurity=True) Returns a shake-256 variable hash object; optionally initialized with a string
algorithms_available = {'sha512_256', 'md5', 'sha3_384', 'sha3_224', 'blake2b', 'blake2s', 'sha512_224', 'shake_256', 'sha1', 'sha256', 'md5-sha1', 'mdc2', 'sha3_256', 'shake_128', 'md4', 'sm3', 'sha3_512', 'sha224', 'sha512', 'ripemd160', 'sha384', 'whirlpool'}
algorithms_guaranteed = {'blake2s', 'sha3_256', 'sha384', 'shake_128', 'md5', 'shake_256', 'sha3_384', 'sha3_512', 'sha3_224', 'sha1', 'sha256', 'blake2b', 'sha224', 'sha512'}