Skip to content

Instantly share code, notes, and snippets.

@alshell7
Last active December 10, 2023 14:48
Show Gist options
  • Save alshell7/981c2e9c4b82b675117b9fa063e65d65 to your computer and use it in GitHub Desktop.
Save alshell7/981c2e9c4b82b675117b9fa063e65d65 to your computer and use it in GitHub Desktop.
Convert given string to SHA1 hash by hexadecimal digest in python
def sha1Hash(toHash):
try:
messageDigest = hashlib.sha1()
stringM = str(toHash)
byteM = bytes(stringM, encoding='utf')
messageDigest.update(byteM)
return messageDigest.hexdigest()
except TypeError:
raise "String to hash was not compatible"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment