📅  最后修改于: 2023-12-03 15:04:05.306000             🧑  作者: Mango
Python hashlib module provides a set of hash functions to calculate the cryptographic hash values of strings or files. One of the hash functions provided by hashlib module is sha512()
.
The sha512()
method creates a SHA-512 hash object. You can use this object to generate the SHA-512 hash value of a message.
Here is an example:
import hashlib
message = "Hello, world!"
hash_object = hashlib.sha512(message.encode('utf-8'))
hex_dig = hash_object.hexdigest()
print(hex_dig)
Output:
397bde29e9f9ac9e48769069cdab09f34e277d7a8b80a95c7e7286d2e01e0478c16f3dc7a398b7ed945853d82bbd507ea5e3e16f174d8eec89c82aae14a52113
In this example, we create a sha512 hash object using the hashlib.sha512()
method. Then we encode the message 'Hello, world!' and calculate its SHA-512 hash using the hexdigest()
method. Finally, we print the SHA-512 hash value in hexadecimal format.
Python hashlib module provides several hash functions to calculate the cryptographic hash value of a message. sha512()
is one such function that returns the SHA-512 hash value of a message. By using the hashlib
module, the hash value of a message can be quickly and easily calculated.