# Create a SHA-224 message print("--SHA224--") m = hashlib.sha224() # Update the hash object with byte_string m.update(byte_string) # Obtain the digest, digest size, and block size print("Msg Digest: {}\nMsg Digest Size: {}\nMsg Block Size: {}".format( m.hexdigest(), m.digest_size, m.block_size)) # Validate the digest against CPython hashlib-sha224 assert ( m.hexdigest() == "744535a10879be6b18bbcdd135032891346f530a7845d580f7869f36" ), "Digest does not match expected string." # SHA-256 print("--SHA256--") m = hashlib.sha256() # Update the hash object with byte_string m.update(byte_string) # Obtain the digest, digest size, and block size print("Msg Digest: {}\nMsg Digest Size: {}\nMsg Block Size: {}".format( m.hexdigest(), m.digest_size, m.block_size)) # Validate the digest against CPython hashlib-sha256 assert (m.hexdigest() == "3ce8334ca39e66afb9c37d571da4caad68ab4a8bcbd6d584f75e4268e36c0954" ), "Digest does not match expected string." # SHA-384 print("--SHA384--") m = hashlib.sha384() # Update the hash object with byte_string m.update(byte_string)
def gen_hash(auth_string): # SHA-256 # Create hash object sha_hash = hashlib.sha256() # Update the hash object with auth_string sha_hash.update(auth_string) return sha_hash.hexdigest()