Untitled

 avatar
unknown
plain_text
19 days ago
688 B
3
Indexable
def encryptpwd(plain_password):
    # 📌 Générer un sel unique (16 octets)
    SALT = os.urandom(16)

    # 📌 Dériver la clé avec PBKDF2-HMAC-SHA512 (correspond à ce que fait pgAdmin)
    KEY = hashlib.pbkdf2_hmac('sha512', MASTER_KEY, SALT, 25000, dklen=32)

    # 📌 Chiffrement AES-GCM
    cipher = AES.new(KEY, AES.MODE_GCM)
    nonce = cipher.nonce  # Nécessaire pour déchiffrement
    ciphertext, tag = cipher.encrypt_and_digest(plain_password.encode())

    # 📌 Respecter la structure de stockage de pgAdmin : Base64(SALT + NONCE + TAG + CIPHERTEXT)
    encrypted_password = base64.b64encode(SALT + nonce + tag + ciphertext).decode()

    return encrypted_password
Editor is loading...
Leave a Comment