« SqWebMail and XMail | Main | lsqlite3 / lsqlcrypt3 »

03 December 2004

PySQLcrypt

PySQLcrypt is an enhanced version of PySQLite that uses SQLcrypt, which itself enhances SQLite version 3 with transparent AES encryption.

This demo distribution for Windows is built from the trial version of SQLcrypt and contains the following files:

_sqlcrypt.pyd            
sqlcrypt/*.py            
crypt_test.py            
crypt_dbapi_txns.py

First, copy _sqlcrypt.pyd and sqlcrypt/*.py into your Python installation's site-packages.

Next, run the unit tests in crypt_test.py:

  C:\> python crypt_test.py
  .........
  ----------------------------------------------------------------------
  Ran 9 tests in 0.660s

  OK

Now try out crypt_dbapi_txns.py. This program is based on dbapi_transactions.py from PySQLite, with the following changes: (1) the database file, 'customerdb', is encrypted; (2) at the end of the program run, the database content is not cleared.

  C:\> python crypt_dbapi_txns.py

  C:\> sqlcrypt3 customerdb
  SQLcrypt version 3.0.7
  Enter ".help" for instructions
  sqlcrypt> .decrypt abcdefgh
  sqlcrypt> .tables
  customer  orders
  sqlcrypt> select * from customer;
  1|Jane|Doe|JD0001
  sqlcrypt> select * from orders;
  1|1|White Towel|2
  2|1|Blue Cup|5
  sqlcrypt> ^Z

  C:\> sqlite3 customerdb "select * from orders"
  SQL error: file is encrypted or is not a database

  C:\> python
  Python 2.3.4 (#53, May 25 2004, 21:17:02) [MSC v.1200 32 bit (Intel)] on win32
  Type "help", "copyright", "credits" or "license" for more information.
  >>> import sqlcrypt
  >>> sqlcrypt.license_key('ZIHKBLID-IACHUSSU-JUPOTCNF-CXYOQSFE')
  >>> cnx = sqlcrypt.connect('customerdb')
  >>> cnx.passphrase('abcdefgh', 0)
  >>> cu = cnx.cursor()
  >>> cu.execute('select * from orders')
  >>> print cu.fetchall()
  [(1, 1, 'White Towel', 2), (2, 1, 'Blue Cup', 5)]
  >>>

To play, download PySQLcrypt for Python 2.3 (Windows) and the SQLcrypt trial version Windows installer.


Posted by ngps at 21:44 | Comments (0) | Trackbacks (0)
Comments
There is no comment.
Trackbacks
Please send trackback to:http://sandbox.rulemaker.net/ngps/169/tbping
There is no trackback.