0

I am generating a sqlitedb file with below code

import sqlite3
conn = sqlite3.connect('../sqlitedb/sample_db.db')

Is there any way I can password protect this file or some kind of security in python or generally in windows so nobody can access it.

6
  • Use SQLCipher to perform encryption and decryption with a password from your python code. Commented Aug 26, 2021 at 11:08
  • 1
    Is it answer for your question? stackoverflow.com/questions/50381616/… Commented Aug 26, 2021 at 11:08
  • 2
    Pointless. Your computer if you are admin (if its a corporate environment you are not), then you can set the permissions which is simple, but then you hardly need to protect. If its on someone else's computer they can just read the python password from your file. Commented Aug 26, 2021 at 11:09
  • @Armaggheddon could you exactly show me as its new for me to use this. Commented Aug 26, 2021 at 11:10
  • @jwal I should use it in someone else's system so I am protecting the python file as well so the code cannot be read or accessed Commented Aug 26, 2021 at 11:11

1 Answer 1

2

This Solution Will Work on Linux OS Only

Install sqlcipher:

sudo apt-get install sqlcipher

Install sqlcipher package:

pip install pysqlcipher3

Sample Code:

from pysqlcipher3 import dbapi2 as sqlite
conn = sqlite.connect('test.db')
c = conn.cursor()
c.execute("PRAGMA key='password'")
c.execute("PRAGMA cipher_compatibility = 3")
c.execute('''create table stocks (date text, trans text, symbol text, qty real, price real)''')
c.execute("""insert into stocks values ('2006-01-05','BUY','RHAT',100,35.14)""")
conn.commit()
c.close()

For Windows You Can Follow Below Links:

  1. Install pysqlcipher3 windows
  2. Compile SQLite with SQLCipher on Windows
Sign up to request clarification or add additional context in comments.

3 Comments

not able to use the sudo command on windows
See at the end of this page. Windows binaries are not provided so you have to compile your own or buy a prebuilt one. Is just easier to use a linux based system.
@shee You follow attached links

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.