Skip to content

Instantly share code, notes, and snippets.

@yongkangc
Created August 16, 2022 14:11
Show Gist options
  • Select an option

  • Save yongkangc/2caacf28674c9a311d556712c5ba178c to your computer and use it in GitHub Desktop.

Select an option

Save yongkangc/2caacf28674c9a311d556712c5ba178c to your computer and use it in GitHub Desktop.
Python Implementation for Hashing with Salting of URI
import uuid
import hashlib
def hashText(secret, uri):
"""
Basic hashing function for a text using unique secret from the user.
"""
return hashlib.sha256(secret.encode() + text.encode()).hexdigest() + ':' + secret
def matchHashedText(hashedUri, Uri):
"""
Check for the uri in the hashed uri
"""
_hashedText, secret = hashedText.split(':')
return _hashedText == hashlib.sha256(secret.encode() + Uri.encode()).hexdigest()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment