₦airaland Forum

Welcome, Guest: RegisterLoginWith GoogleTrendingRecentNew

Stats: 3,325,475 members, 8,422,265 topics. Date: Monday, 08 June 2026 at 12:19 AM

Toggle theme

Gmus's Posts

Nairaland ForumGmus's ProfileGmus's Posts

1 2 3 (of 3 pages)

ProgrammingRe: Anybody Here Know How One Can Password/encrypt Sqlite Database in C++? by gmus: 12:52pm On Jun 14, 2015
seunthomas:
Dude you are not a learner but let me break it down to you. In most sqlite libraries you have an option to specify the filename for the db. Now the idea of locking the file is so no one can access it while your are making edits. The temp file is so your application thread can still make edits like do an insert. The default file name of sqlite is .db and in some cases no extension. Its simple. You just create a function that does this for you. I cant give u the details.

char[] openFileWithLock(char *filename){

//do your implementation here
//decrypt the file
return filename(so your application can work with the file(.tmp)
}
//your file would be converted back to .db or whatever extension
void releaseFileLock(){
//encrypt the file
}
void decryptFile(char *filename){
//decrypt the file
}
void encryptFile(char *filename){
//encrypt the file
}
I understand what u are saying perfectly well now. I actually wrote a similar implementation dt did not work. I use CppSQLite3 C++ wrapper for sqlite. Apart from d fact dt i used a mutex to ensure read lock and d fact that i used another file with a name formed usung the name of d actual db file, my implentation and yours are identical. However each time i attempt to copy d (now) re-encrypted file back to d database file, an exception is thrown.
ProgrammingRe: Anybody Here Know How One Can Password/encrypt Sqlite Database in C++? by gmus: 12:30pm On Jun 14, 2015
seunthomas:
http://stackoverflow.com/questions/853805/locking-files-using-c-on-windowshttps://msdn.microsoft.com/en-us/library/windows/desktop/aa363858(v=vs.85).aspx#caching_behavior
The idea of locking the file is so that no one else can access it while you use it.
Also depend on the library you can also lock the db from sqlite. https://www.sqlite.org/lockingv3.html But since you want to encrypt the database this wont be appropriate.
I suppose dt this what you mean

https://msdn.microsoft.com/en-us/library/windows/desktop/aa363858(v=vs.85).aspx#caching_behavior
ProgrammingRe: Anybody Here Know How One Can Password/encrypt Sqlite Database in C++? by gmus: 12:28pm On Jun 14, 2015
seunthomas:
http://stackoverflow.com/questions/853805/locking-files-using-c-on-windows
The idea of locking the file is so that no one else can access it while you use it.
Also depend on the library you can also lock the db from sqlite. https://www.sqlite.org/lockingv3.html But since you want to encrypt the database this wont be appropriate.
I suppose dt this what you mean
ProgrammingRe: Anybody Here Know How One Can Password/encrypt Sqlite Database in C++? by gmus: 12:04pm On Jun 14, 2015
seunthomas:
http://stackoverflow.com/questions/853805/locking-files-using-c-on-windows
The idea of locking the file is so that no one else can access it while you use it.
Also depend on the library you can also lock the db from sqlite. https://www.sqlite.org/lockingv3.html But since you want to encrypt the database this wont be appropriate.
It is not locking files that is strange to me, it is opening it in the temporary mode using the extension you gave that is strange to me.
ProgrammingRe: Anybody Here Know How One Can Password/encrypt Sqlite Database in C++? by gmus: 11:48am On Jun 14, 2015
gimakon:
Are you encrypting a string or the database itself?
Actually, because I couldn't encrypt that database it self or password it, I am at the moment, encrypting the strings as I learnt through google search, but any body who knows what to do can see view the schema of my database, now that is a large security hole that I have been worried about.

I wish to encrypt the entire database.
ProgrammingRe: Anybody Here Know How One Can Password/encrypt Sqlite Database in C++? by gmus:
seunthomas:
Steps:
a. Open the sqlite database file in read lock mode as a temporary file(e.g appdb.db.tmp) .
b. Modify the data in the database.
c. With the file handle you have opened, encrypt the file.
d. Write the encypted file to app.db and delete app.db.tmp.
Now this is funny, I have been programming in C++ for years but do not think I know how to open a file in read lock mode as temporary file as u indicated here. Is the highlighted operation an SQLite operation or a normal c++ file operation or a Win32/MFC operation? By the way I am using MFC for this app and it means I am programming for windows.

If it is an SQLite3 operation I could quickly check the manual online and get the details, but if it a c++ file operation, I am afraid I don't know it and I will really appreciate it if you can give me a brief explantion on that. I assure that I will quickly get the gist if you give me a brief explanation. Even though I am progrmming with MFC, I can use any C/C++ construct that I desire.

The lesson, I am learning today is never to underrate nairaland. Many popular glabally acclaimed forum that I belong to have failed me. So also has google on this. Talk of something being in the pocket of your sokoto....

Please, friend kindly help me with more detailed info as requested.



After thought:
Since you used the word "handle" I am assuming it a win32/MFC file open operation. I am checking that up now. This doesn't however mean you should no longer give the requested additional detail.

1 2 3 (of 3 pages)