Created
August 16, 2022 14:11
-
-
Save yongkangc/2caacf28674c9a311d556712c5ba178c to your computer and use it in GitHub Desktop.
Python Implementation for Hashing with Salting of URI
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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