File size: 815 Bytes
eefbb54 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
import os
from dotenv import load_dotenv
import hashlib
import json
# Load the .env file
load_dotenv()
# Get the encryption key (salt)
encryption_salt = os.getenv("EMAIL_ENCRYPTION_KEY").encode()
# Function to deterministically hash emails
def deterministic_hash(email, salt):
return hashlib.pbkdf2_hmac("sha256", email.encode(), salt, 100000).hex()
# Load emails from private/students.json
with open("private/students.json", "r") as file:
emails = json.load(file)
# Replace emails with deterministic hashed emails, {hashed_email: [roles]}
hashed_emails = {
deterministic_hash(email, encryption_salt): roles for email, roles in emails.items()
}
# Save hashed emails to private/students_encrypted.json
with open("private/students_encrypted.json", "w") as file:
json.dump(hashed_emails, file)
|