Leslie Holm
Leslie Holm

Reputation: 1

Sqlcipher3 function rekey doesn´t seem to work?

I´m using python 3.12 and sqlite3 and sqlcipher3 community. My IDE is PyCharm Community 2023.3.5. When trying to rekey nothing happens and no error is shown! The database is not empty. Anyone had the same problem? All suggestions are appreciated.

Here is my code.

def change_key(current_key, new_key):
try:
    print(current_key, new_key) # Values are correct
    conn = sqlite3.connect("test.db")
    cur = conn.cursor()    
    cur.execute("PRAGMA cipher_compatibility = 3")
       
    cur.execute("PRAGMA key = '{}'".format(current_key))

    # Rekey the database with the new key

    cur.execute("PRAGMA rekey = '{}'".format(new_key))

    # Commit changes and close the connection
    conn.commit()
    conn.close()
except Error as e:
    print(e)

I have tried a lot of different solutions but whatever I do the key stays the same. It´s driving me nuts!

Upvotes: 0

Views: 54

Answers (0)

Related Questions