create a sha512 hash from a string in python

To create a SHA512 hash from a string in Python, you can use the cryptography library which provides a secure way to generate hashes.

Here's an example code snippet:

main.py
import hashlib

def sha512_hash(string):
    sha512 = hashlib.sha512()
    sha512.update(string.encode('utf-8'))
    return sha512.hexdigest()
143 chars
7 lines

This function takes a string as input and returns a SHA512 hash in hexadecimal format. It uses the hashlib module to create a new SHA512 object, updates it with the input string after encoding it to bytes, and finally returns the hexadecimal digest of the hash using the hexdigest() method.

gistlibby LogSnag