How can I password protect my sqlite db in C. Is it possible to split sqlite db?

I am working on an embedded system and the device has a linux kernel with sqlite database. I wanted to know if the sqlite database can be divided into safe and normal partitions.

How can I provide encryption for the sqlite database file in linux.

0
sqlite
Jan 13 2018-11-11T00:
source share
3 answers

David Single, Product Management Director for Berkeley DB.

A recent release of Oracle Berkeley DB 5.1 (5.1.7) integrates Berkeley DB encryption with the SQLite-based SQL API. You can read about it here .

0
Jan 14 2018-11-11T00:
source share

for the encryption to be achieved with SQLite, you need to license some extensions from the author of SQLite.

http://www.sqlite.org/support.html

0
Jan 15 '11 at 0:30
source share

I may be too late to answer this question, but I have encountered this problem since two days and have not found a reliable solution on the Internet. I found a solution, so I share it.

// Steps to authenticate sqlite database

  • download zip file with sqlite3 amalgam

  • unzip the file. The file should contain shell.c, sqlite3.c, sqlite3.h, sqlite3ext.h

  • click find link here

3a. Open userauth.c and copy all the code and paste it at the end of your sqlite3.c file.

3b. Open sqlite3userauth.h and copy all the code and run it at the end of your sqlite3.h file.

  1. create an output file to execute the command in the shell command: gcc -o sqlite3Exe shell.c sqlite3.c -DSQLITE_USER_AUTHENTICATION -ldl -lpthread

4a. In the shell.c file you get the error message "sqlite3userauth.h": Solution: go to this file and comment on it. (this is because you already included the necessary code when copying sqlite3auth.h to sqlite3.h)

4b. Test your output file by running ./sqlite3Exe (this is the name given to the output file generated in the previous step). you will get sqlite console.

4s Create the database and authentication flag:

command1: .open dbname.db

command2: .auth on

command3: .exit // command 3 is optional

  1. Building library 5a: creating an object file // Compile sqlite3.c to create an object after adding our new code

: gcc -o sqlite3.o -c sqlite3.c -DSQLITE_USER_AUTHENTICATION

With this command, we create an object file that we can use to compile our c file.

  1. Create a c file to authenticate your database:

      //authUser.c
    
    

    include "stdio.h"

    include "stdlib.h"

    include "sqlite3.h"

    int main (int argc, char * argv []) {int a = 10; int rtn, rtn2; sqlite3 * db; char * sql, * zErMsg; rtn = sqlite3_open ("dbname.db", & db); rtn = sqlite3_user_add (db, "username", "password", 2, 1); // last, but one parameter for the number of bytes for the password, the last parameter for the weather, which the user is an administrator or not if (RTN) {fprintf (stderr, "Unable to open database:% s \ n", sqlite3_errmsg (db)); Return (0); } More {fprintf (stderr, "Secured Database Successfully \ n"); } sqlite3_close (dB); return 0; } Pre> `

  2. Compiling the program // Compiling the program command1: gcc authUser.c sqlite3.o -lpthread -ldl command2: ./a.out // Exit: the protected database was successful

  3. create c file to create a table if the user is authenticated

      //createTable.c
    
    

    include "stdio.h"

    include "stdlib.h"

    include "sqlite3.h"

    static int callback (void * NotUsed, int argc, char ** argv, char ** azColName) {int i; for (i = 0; I am less than argc; I ++) {printf ("% s =% s \ n", azColName [i], argv [i]? argv [i]: "NULL"); } E ("\ n"); return 0; } int main (int argc, char * argv []) {int a = 10; int rtn, rtn2; sqlite3 * db; char * sql, * zErMsg; rtn = sqlite3_open ("dbname.db", & db); rtn = sqlite3_user_authenticate (db, "user", "password", 2); if (RTN) {fprintf (stderr, "Cannot open the database:% s \ n", sqlite3_errmsg (db)); Return (0); } More {fprintf (stderr, "successfully open database \ n"); } sql = "create table newtable (id int not null primary key, name varchar (100) not null)"; // sql = "insert into newtable values ​​(5, 'ishwar')"; rtn = sqlite3_exec (db, sql, callback, 0, & zErMsg); if (rtn! = SQLITE_OK) {sqlite3_free (zErMsg); } More {fprintf (stdout, "The table was created successfully \ n"); // fprintf (stdout, "successfully inserted \ n"); } sqlite3_close (dB); return 0; } Pre> `

  4. compilation of the program // Compilation of the program

command1: gcc createTable.c sqlite3.o -lpthread -ldl

command2: ./a.out // Conclusion: the table was created successfully

  1. Create c file to add values ​​to table

from the previous code you can see two sql variables and two fprintf inside else, now uncomment the commented line and comment on the other. and execute the same command as above output: successfully inserted

And you did, try experimenting with the code, change the values ​​of the sqlite3_user_authenticate function, with which you cannot perform these operations, with the maximum possibility of opening the database (when you comment on sqlite3_user_authenticate functon.nothing else)

  1. Shell Testing

Run the command: ./sqlite3Exe (the output file created in step 4)

command1: .open dbname.db

command2: .tables // you should get an error, user_auth

Thank you (please write to me in case of any problems: ishwar.rimal@gmail.com)

0
Nov 23 '16 at 11:42 on
source share



All Articles