The sha12() function of hashlib module in Python

The sha12() function returns the 512 bit message digest for a given message as computed by the SHA-12 cryptographic algorithm.

Hashlib Module Updated 25 Apr 2026 1 min read

Example

python
# Example Python program that produces a

            # SHA-512 message digest for a given text

            # using the Python hashlib module

            import hashlib

# The text for which SHA-512 hash is needed

            text1AsBytes    = b"Pat-a-cake, pat-a-cake baker's man"

# Compute SHA-512 hash

            sha512Hash         = hashlib.sha512(text1AsBytes)

# Print the text and hash

            print("Text:")

            print(text1AsBytes.decode())

print("SHA-512 hash in hexadecimal format:")

            print(sha512Hash.hexdigest())

print("SHA-512 hash in binary format:")

            print(sha512Hash.digest())

print("Message digest length (in bits):")

            print(sha512Hash.digest_size * 8)

print("Message digest length (in bytes):")

            print(len(sha512Hash.digest()))

            print(type(sha512Hash.digest()))

Output

Output
Text:

            Pat-a-cake, pat-a-cake baker's man

            SHA-512 hash in hexadecimal format:

            a9720cd87148954fd99869300c251a9c9f34de75f942764af5901ca60c456febd33a5cbc99b3bb4e419b2882f888ef04e6aecea05e3515686c13ee1b4d24b01d

            SHA-512 hash in binary format:

            b'\xa9r\x0c\xd8qH\x95O\xd9\x98i0\x0c%\x1a\x9c\x9f4\xdeu\xf9BvJ\xf5\x90\x1c\xa6\x0cEo\xeb\xd3:\\\xbc\x99\xb3\xbbNA\x9b(\x82\xf8\x88\xef\x04\xe6\xae\xce\xa0^5\x15hl\x13\xee\x1bM$\xb0\x1d'

            Message digest length (in bits):

            512

            Message digest length (in bytes):

            64

            <class 'bytes'>