import sqlite3
from Crypto.Cipher import AES

# 🔑 You MUST provide the correct AES key here (bytes)
# Example: key = b'\x01\x02...'
key = bytes.fromhex('c7f1ad7b079947b4bb1dc53b8740440651b6c9f5caf7fd9a18bbece57c7bd444')

db_path = "Login Data"

def decrypt_password(encrypted_password, key):
    try:
        if encrypted_password.startswith(b'v10'):
            nonce = encrypted_password[3:15]
            ciphertext_tag = encrypted_password[15:]
            ciphertext = ciphertext_tag[:-16]
            tag = ciphertext_tag[-16:]

            cipher = AES.new(key, AES.MODE_GCM, nonce=nonce)
            decrypted = cipher.decrypt_and_verify(ciphertext, tag)
            return decrypted.decode('utf-8')
        else:
            return "<unsupported format>"
    except Exception as e:
        return f"<decrypt error: {e}>"

def main():
    conn = sqlite3.connect(db_path)
    cursor = conn.cursor()

    cursor.execute("""
        SELECT username_value, password_value
        FROM logins
    """)

    for username, encrypted_password in cursor.fetchall():
        if encrypted_password:
            password = decrypt_password(encrypted_password, key)
        else:
            password = ""

        print(f"Username: {username}")
        print(f"Password: {password}")
        print("-" * 40)

    conn.close()

if __name__ == "__main__":
    main()