I'd like a method of hashing an email (just the address) using a unique key. So the flow would be the next one:
- I receive an email address.
- I am using that key (along with a hashing algorithm) to hash the email, and then I store that hash in the DB
- If the same email will try to sign in, the same hash method will be applied but it will match the existing one in the database. If it's a new email, store again the hash in DB and so on.
Now, I know about hashlib and its basic implementation:
import hashlib
email = '[email protected]'
key = '1234'
hash_object = hashlib.sha256(email)
print(key + hash_object.hexdigest())
Now, I don't know how secure is this implementation as it's always adding key in front of my hash.
My wish is to have a unique key (which will be stored somewhere), and always hash an email using it. More, I don't want to ever decode that hash. I'm just interested in encoding it.
Any ideas ?
xchars are the same, so the key is already compromised