main_9.py 682 B

123456789101112131415161718192021
  1. def pseudonymize_2(value, salt=SALT_KEY):
  2. """Pseudonymize value with salt, using HMAC-SHA256 encoding
  3. Parameters
  4. ----------
  5. value: value to be pseudonymized
  6. salt: hazard salt for additional protection
  7. Returns
  8. -------
  9. pseudonymized value using HMAC-SHA256
  10. """
  11. # NOTE: Here we must bypass empty or None value as
  12. # it will introduce specific hash value
  13. if value is None or value is np.nan or value == '':
  14. return None
  15. return hmac.new(
  16. key=salt.encode('utf-8'), # La clé
  17. msg=str(value).encode('utf-8'), # La donnée à pseudonymiser
  18. digestmod=hashlib.sha256 # La fonction de hash
  19. ).hexdigest()