Results 1 to 6 of 6

Thread: Encrypting an existing sqlite database in sqlcipher

  1. #1
    Join Date
    Apr 2011
    Posts
    67
    Thanks
    22
    Thanked 5 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Encrypting an existing sqlite database in sqlcipher

    I am using sql cipher in Qt and i want to encrypt an existing sqlite database.On the Api docs here: http://sqlcipher.net/sqlcipher-api#attach this is how to do it:

    Qt Code:
    1. ATTACH DATABASE 'encrypted.db' AS encrypted KEY 'secret'; -- create a new encrypted database
    2. CREATE TABLE encrypted.t1(a,b); -- recreate the schema in the new database (you can inspect all objects using SELECT * FROM sqlite_master)
    3. INSERT INTO encrypted.t1 SELECT * FROM t1; -- copy data from the existing tables to the new tables in the encrypted database
    4. DETACH DATABASE encrypted;
    To copy to clipboard, switch view to plain text mode 

    The following two line confuse me:

    CREATE TABLE encrypted.t1(a,b);

    and

    INSERT INTO encrypted.t1 SELECT * FROM t1;

    What does (a,b) mean and why is it used in the first statement and not in the second?.

    Thanks.


    Added after 1 40 minutes:


    Someone has suggested to me that the a,b could be table columns.I am looking into that.
    Last edited by thefatladysingsopera; 18th October 2011 at 18:16.

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Encrypting an existing sqlite database in sqlcipher

    "(a, b)" is the columns. Since the original t1, and the encrypted.t1 have an identical schema then "select * from t1" will produce columns in exactly the same order as in the definition of encrypted.t1 so a column list is not required.

  3. #3
    Join Date
    Apr 2011
    Posts
    67
    Thanks
    22
    Thanked 5 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Encrypting an existing sqlite database in sqlcipher

    Hello Chris,thanks.I have the sql cipher driver working fine but i cannot create an encrypted database yet.Lets put aside the attach database method for a moment.What other method is there to make an encrypted database?.

    Qt Code:
    1. QSqlDatabase db = QSqlDatabase::addDatabase("QSQLCIPHER");
    2. db.setDatabaseName(/*add the database path here*/);
    3. if (!db.open())
    4. qFatal("Could not access database.");
    5. QSqlQuery query(db);
    6. query.exec("PRAGMA key = 'secretkey';");
    To copy to clipboard, switch view to plain text mode 

    In this example http://www.qtcentre.org/wiki/index.p...yption_support there is no mention of creating an encrypted database i have noted.

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Encrypting an existing sqlite database in sqlcipher

    That looks good to me. What is the problem? The new database will be zero bytes until you actually define some tables in it.

  5. #5
    Join Date
    Apr 2011
    Posts
    67
    Thanks
    22
    Thanked 5 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Encrypting an existing sqlite database in sqlcipher

    I will try keying the database using the command shell and creating some tables and i will report back what i get.The problem i had is that the database wasn't being encrypted.

  6. #6
    Join Date
    Apr 2011
    Posts
    67
    Thanks
    22
    Thanked 5 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Qt Encrypt/Decrypt Example

    I have re-evaluated my applications needs and have resolved to put aside the sqlite encryption and to obscure only parts that are of paramount importance such as start of trial dates etc.
    The driver sql cipher i believe is still very good and i shall resume from where i left off in the future but as of now i have another solution which works just fine.

    @Chris tried keying the database from the sqlite windows shell but the database is not being encrypted.I have decided to try some other day since i have lots of class work to do.

    Thanks.

    ned.zip
    Last edited by thefatladysingsopera; 21st October 2011 at 19:22.

Similar Threads

  1. AES-256 encrypted SQLite databases with SQLCipher
    By Lykurg in forum Installation and Deployment
    Replies: 10
    Last Post: 29th July 2011, 03:22
  2. Sqlite Database
    By sabbu in forum Qt Programming
    Replies: 5
    Last Post: 16th May 2011, 13:07
  3. How to insert row to SQLite database?
    By MIH1406 in forum Qt Programming
    Replies: 6
    Last Post: 29th May 2010, 12:22
  4. Encrypting and decrypting with QCA
    By s.g. in forum Qt Programming
    Replies: 1
    Last Post: 6th December 2009, 20:41
  5. [QT4][SQLITE] Database and query
    By agent007se in forum Newbie
    Replies: 10
    Last Post: 12th July 2006, 22:16

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.