Encrypt/Hide sqlite3 database (Tkinter & Python)

Question:

I am currently working on a password saving application using tkinter, and I don’t want the database to be visible/accesible from the computer’s local storage. Is there a way to achieve this with a pre-existing python library, or do I have to pay for a service?

Asked By: SShield

||

Answers:

You can try encrypting your database. I’m fairly sure sqlite doesn’t offer encryption by default, you might need an extension like SQLCipher.

Answered By: yanjunk

If you are looking for a password verification system, you could use one-way hashes like Sha256 or a salted algorithm. If you need a password manager, you could use PyCryptoDomex to encrypt the user’s password with a "master key" that the user has to remember. Then when you want to fetch a passcode, ask them for the master key again and use it to decrypt the password.

Answered By: thepronoobkq

you can use Sqlite3En package or SQLCipher
Sqlite3En doc:

https://github.com/yous1010/Sqlite3En_python/tree/master

SQLCipher :

https://www.zetetic.net/sqlcipher/

A simple example for sqlite3En :
To Encript db :

from Sqlite3En import Sqlite3En
Sqlite3En.Encrypt_existing_DB_By_Password('DBfile1\' , 'DBName.db' ,'Table_Name' , password = 'password' ) #DBfile1\ is DB path folder

To open and connect Encrypted DB :

Memory_conn = sqlite3.connect(":memory:")
Sqlite3En.Open_Encrypted_DB_By_Password ('DBfile1\','DBName.db','Table_Name',Memory_conn , password = 'password' )

now you can use sqlite db as usual

to select data :

Memory_conn.execute("SELECT * FROM Table_Name) 

To insert new value in DB:

Memory_conn.execute("INSERT INTO Table_Name (ID,NAME,AGE) VALUES (1, 'sam', 35)");
Memory_conn.commit()
Sqlite3En.Save_Change_On_EnDB_By_Password(Memory_conn,'DBName.db','Table_Name','DBfile1\',password = 'password' )
Answered By: yam ka
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.