As we've seen in earlier posts, you can create an SHA-512 hash of a string and generate a hash in string type. But, what if you had to create an integer out of it? Practical real-world use-cases can be - if you have a unique integer ID that you have in your database which you can map.
import hashlib import uuid hash = hashlib.sha512('some string'.encode('utf-8')) a = uuid.UUID(hash.hexdigest()[::4]) print(a)
In the above code, you can see that we are passing the hash string to the
uuid.UUID, which returns the UUID value of the SHA-512 hash.
The output of the above code will be a UUID-
I'm glad that you found this article to create UUID from a SHA256 hash string useful. Happy Coding.