# Problem with rekey

**URL:** https://discuss.zetetic.net/t/problem-with-rekey/6408
**Category:** SQLCipher
**Created:** [April 20, 2024, 8:07am UTC](https://discuss.zetetic.net/t/problem-with-rekey/6408 "2024-04-20T08:07:25Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Leslie\_Holm](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.zetetic.net/leslie_holm/32/2206_2.png) [@Leslie\_Holm](https://discuss.zetetic.net/u/Leslie_Holm)
#### Post date: [April 20, 2024, 8:07am UTC](https://discuss.zetetic.net/t/problem-with-rekey/6408/1 "2024-04-20T08:07:25Z")

</div>

Hi 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 an no error is shown! The database is not empty.  
As you can see I have tried many different ways. 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 = create_connection()
    cur = conn.cursor()
    # cur.execute("PRAGMA key = '{}'".format(current_key))

    # cur.execute("PRAGMA cipher_compatibility = 3")
    # cur.execute(f"PRAGMA key = '{current_key}'")
   
       cur.execute("PRAGMA key = '{}'".format(current_key))

    # Rekey the database with the new key
    # cur.execute(f"PRAGMA rekey = '{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)

```

---

<div class="post-metadata">

### Author: ![sjlombardo](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.zetetic.net/sjlombardo/32/3_2.png) [@sjlombardo](https://discuss.zetetic.net/u/sjlombardo)
#### Post date: [April 22, 2024, 9:10pm UTC](https://discuss.zetetic.net/t/problem-with-rekey/6408/2 "2024-04-22T21:10:53Z")

</div>

When you say nothing happens, are you still able to open the database using the old key value?

---

<div class="post-metadata">

### Author: ![Leslie\_Holm](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.zetetic.net/leslie_holm/32/2206_2.png) [@Leslie\_Holm](https://discuss.zetetic.net/u/Leslie_Holm)
#### Post date: [April 23, 2024, 5:23am UTC](https://discuss.zetetic.net/t/problem-with-rekey/6408/3 "2024-04-23T05:23:42Z")

</div>

Yes no problem. Yesterday I finally managed to compile sqlcipher and got sqlite3 exe and dll. I will try with them but I don’t know how to get them to work in Pycharm. Where do I put them? Shall I still import sqlcipher in the code?

Leslie
