create a blake2s hash from a string in python

To create a blake2s hash from a string in Python, you will need to utilize the cryptography library. Here's an example code snippet:

main.py
from cryptography.hazmat.primitives import hashes

def create_blake2s_hash(string_to_hash):
    blake2s_hash = hashes.Hash(hashes.BLAKE2s(32))
    blake2s_hash.update(string_to_hash.encode("utf-8"))
    return blake2s_hash.finalize()
234 chars
7 lines

You can then call the function create_blake2s_hash() with a string input to get the corresponding blake2s hash. For example:

main.py
string_to_hash = "this is a string to hash"
blake2s_hash = create_blake2s_hash(string_to_hash)
print(blake2s_hash.hex())
121 chars
4 lines

This will output the hexadecimal representation of the blake2s hash of the input string.

gistlibby LogSnag