Python Snippet to Hash Email Addresses

I wanted to process some email address data today but hide the real email addresses. To do that I chose to run the SHA-256 hash over the email address data. Here’s the python snippet I used to convert the plain emails to the hashed versions (ignoring any emails with anything other than ASCII characters for simplicity):


import hashlib

plain_emails = ["user1@address1",
                "user2@address2"]

hashed_emails = [hashlib.sha256(bytes(mail.lower(), "ascii")).hexdigest()
                 for mail
                 in plain_emails]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s