Pseudonymization with keyed-hash function in Python and AWS

Table of Contents

Step 1: AWS KMS

Navigate to and click Create a key button:

Step 2: AWS Secrets Manager

Navigate to and click Store a new secret button:

Step 3: Python

Pseudonymize e-mail address with keyed-hash function in Python.

import hashlib
import json
import boto3
email = ''
secretsmanager = boto3.client('secretsmanager')
response = secretsmanager.get_secret_value(SecretId='Medium')
secret_string = response['SecretString']
hash_key = json.loads(secret_string)['hash_key']
sha3 = hashlib.sha3_512()
data = email + hash_key
digest = sha3.hexdigest()



Python Developer and Artificial Intelligence Engineer

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store