Untitled
def encryptpwd(plain_password): # 📌 Générer un sel unique SALT = os.urandom(16) # 📌 Fonction HMAC pour PBKDF2 def hmac_sha512(password, salt): return hmac.new(password, salt, hashlib.sha512).digest() # 📌 Utiliser PBKDF2 avec HMAC-SHA512 correctement référencé KEY = PBKDF2(MASTER_KEY, SALT, dkLen=32, count=25000, hmac_hash_module=hmac_sha512) # 📌 Chiffrement AES-GCM cipher = AES.new(KEY, AES.MODE_GCM) ciphertext, tag = cipher.encrypt_and_digest(plain_password.encode()) # 📌 Encodage en base64 (format utilisé par pgAdmin) encrypted_password = base64.b64encode(SALT + cipher.nonce + tag + ciphertext).decode() return encrypted_password
Leave a Comment