Construct sqlcipher sqlite files for minimal.

Talk here about issues with one of the components hosted at wxCode, or suggest features for it.
Post Reply
dkaip
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 237
Joined: Wed Jan 20, 2010 1:15 pm

Construct sqlcipher sqlite files for minimal.

Post by dkaip » Sun Feb 23, 2020 1:41 pm

Hello.
How i can construct sqlcipher-1.1.8-testkey.db file?
As i see with minimal all sqlcipher files don't construct from scratch but there are in samples folder.
There is a way to make these files?
Thank you.
Jim.

*BTW run minimal from sources with C::B on Linux Mint.
I can not try to Windows get.
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_project_file>
<FileVersion major="1" minor="6" />
<Project>
<Option title="wxSqlite3Minimal" />
<Option pch_mode="2" />
<Option compiler="gcc" />
<Build>
<Target title="Debug">
<Option output="bin/Debug/1" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Debug/" />
<Option type="1" />
<Option compiler="gcc" />
<Option use_console_runner="0" />
<Option projectLinkerOptionsRelation="2" />
<Compiler>
<Add option="-std=c++14" />
<Add option="-g" />
</Compiler>
</Target>
<Target title="Release">
<Option output="bin/Release/1" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Release/" />
<Option type="0" />
<Option compiler="gcc" />
<Option projectLinkerOptionsRelation="2" />
<Compiler>
<Add option="-O2" />
</Compiler>
<Linker>
<Add option="-s" />
<Add option="-ldl" />
</Linker>
</Target>
</Build>
<Compiler>
<Add option="-Wall" />
<Add option="-std=c++14" />
<Add option="`wx-config --cflags`" />
<Add option="-DTHREADSAFE=1" />
<Add option="-DSQLITE_MAX_ATTACHED=10" />
<Add option="-DSQLITE_SOUNDEX" />
<Add option="-DSQLITE_ENABLE_COLUMN_METADATA" />
<Add option="-DSQLITE_HAS_CODEC=1" />
<Add option="-DCODEC_TYPE=CODEC_TYPE_CHACHA20" />
<Add option="-DSQLITE_SECURE_DELETE" />
<Add option="-DSQLITE_ENABLE_FTS3" />
<Add option="-DSQLITE_ENABLE_FTS3_PARENTHESIS" />
<Add option="-DSQLITE_ENABLE_FTS4" />
<Add option="-DSQLITE_ENABLE_FTS5" />
<Add option="-DSQLITE_ENABLE_JSON1" />
<Add option="-DSQLITE_ENABLE_RTREE" />
<Add option="-DSQLITE_CORE" />
<Add option="-DSQLITE_ENABLE_EXTFUNC" />
<Add option="-DSQLITE_ENABLE_CSV" />
<Add option="-DSQLITE_ENABLE_SHA3" />
<Add option="-DSQLITE_ENABLE_CARRAY" />
<Add option="-DSQLITE_ENABLE_FILEIO" />
<Add option="-DSQLITE_ENABLE_SERIES" />
<Add option="-DSQLITE_TEMP_STORE=2" />
<Add option="-DSQLITE_USE_URI" />
<Add option="-DSQLITE_USER_AUTHENTICATION" />
<Add option="-DwxUSE_DYNAMIC_SQLITE3_LOAD=0" />
<Add option="-DWXSQLITE3_HAVE_METADATA=1" />
<Add option="-DWXSQLITE3_USER_AUTHENTICATION=1" />
<Add option="-DWXSQLITE3_HAVE_CODEC=1" />
<Add option="-DWXSQLITE3_HAVE_LOAD_EXTENSION=0" />
<Add directory="../../wxsqlite3" />
<Add directory="../../wxsqlite3/src" />
<Add directory="../../wxsqlite3/include" />
<Add directory="../../wxsqlite3/sqlite3secure/src" />
</Compiler>
<Linker>
<Add option="`wx-config --libs`" />
<Add option="-ldl" />
</Linker>
<Unit filename="../include/wx/wxsqlite3.h" />
<Unit filename="../include/wx/wxsqlite3_version.h" />
<Unit filename="../include/wx/wxsqlite3def.h" />
<Unit filename="../include/wx/wxsqlite3dyn.h" />
<Unit filename="../include/wx/wxsqlite3opt.h" />
<Unit filename="minimal.cpp" />
<Unit filename="../sqlite3secure/src/sqlite3secure.c">
<Option compilerVar="CC" />
</Unit>
<Unit filename="../sqlite3secure/src/sqlite3secure.h" />
<Unit filename="../src/wxsqlite3.cpp" />
<Extensions>
<envvars />
<code_completion />
<lib_finder disable_auto="1" />
<debugger />
</Extensions>
</Project>
</CodeBlocks_project_file>

utelle
Moderator
Moderator
Posts: 927
Joined: Tue Jul 05, 2005 10:00 pm
Location: Cologne, Germany
Contact:

Re: Construct sqlcipher sqlite files for minimal.

Post by utelle » Sun Feb 23, 2020 4:20 pm

dkaip wrote:
Sun Feb 23, 2020 1:41 pm
How i can construct sqlcipher-1.1.8-testkey.db file?
As i see with minimal all sqlcipher files don't construct from scratch but there are in samples folder.
There is a way to make these files?
Those SQLCipher test database files are included for convenience. They were simply copied from the [SQLCipher repository](https://github.com/sqlcipher/sqlcipher).

If you need further assistance, please describe what you want to accomplish and/or where you experience problems.

dkaip
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 237
Joined: Wed Jan 20, 2010 1:15 pm

Re: Construct sqlcipher sqlite files for minimal.

Post by dkaip » Sun Feb 23, 2020 5:23 pm

Can add this library to wxSQLite3 lib to have the ability to construct cipher databases?

Thank you
Jim.

utelle
Moderator
Moderator
Posts: 927
Joined: Tue Jul 05, 2005 10:00 pm
Location: Cologne, Germany
Contact:

Re: Construct sqlcipher sqlite files for minimal.

Post by utelle » Sun Feb 23, 2020 6:11 pm

dkaip wrote:
Sun Feb 23, 2020 5:23 pm
Can add this library to wxSQLite3 lib to have the ability to construct cipher databases?
The SQLite encryption extension coming with wxSQLite3 supports all SQLCipher encryption schemes from version 1 up to version 4. That is, you don't need the SQLCipher library to be able to create, read and write database files using the SQLCipher encryption scheme.

In fact, wxSQLite3 allows to select the encryption scheme at runtime. The following encryption schemes are currently supported:
  • AES 128-bit (first encryption scheme introduced by wxSQLite3)
  • AES 256-bit (second encryption scheme introduced by wxSQLite3)
  • ChaCha20-Poly1305 (as introduced by sqleet) - now the wxSQLite3 default, but default can be changed at compile time
  • SQLCipher AES 256-bit version 1 to 4 (as supported by Zetetic's SQLCipher library)
  • RC4 (as supported by System.Data.SQLite) - not yet officially released, but available in trunk

dkaip
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 237
Joined: Wed Jan 20, 2010 1:15 pm

Re: Construct sqlcipher sqlite files for minimal.

Post by dkaip » Tue Feb 25, 2020 6:57 am

There is a practical example to construct for example sqlcipher-1.1.8-testkey.db or other file?
Thank you
Jim.

utelle
Moderator
Moderator
Posts: 927
Joined: Tue Jul 05, 2005 10:00 pm
Location: Cologne, Germany
Contact:

Re: Construct sqlcipher sqlite files for minimal.

Post by utelle » Tue Feb 25, 2020 11:29 am

dkaip wrote:
Tue Feb 25, 2020 6:57 am
There is a practical example to construct for example sqlcipher-1.1.8-testkey.db or other file?
Well, in principle the minimal sample shows you, how to set up a specific encryption scheme, and if you open a new database (instead of an existing one), you can create your own encrypted database.

The following link shows you some more details about the wxSQLite3 encryption extension.

dkaip
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 237
Joined: Wed Jan 20, 2010 1:15 pm

Re: Construct sqlcipher sqlite files for minimal.

Post by dkaip » Sat Mar 07, 2020 5:09 pm

Hello.
Suppose i have the code bellow ...

Code: Select all

wxSQLite3Database* initDB(void)
{
    wxString testDBName = wxS("dub.db");
    wxSQLite3Database* db = new wxSQLite3Database();
    db->Open(testDBName);
    if (!wxFileExists(testDBName))
    {
        db->UserAdd(wxS("user"), wxS("pswd"), true);
        db->UserLogin(wxS("user"), wxS("pswd"));
        db->ExecuteUpdate(wxS("CREATE TABLE texts (txt char(200))"));
        db->ExecuteUpdate(wxS("insert into texts values ('txt')"));
    }
    return db;
}
How i can take dub.db encrypted with any cipher type?

Thank you
Jim.

utelle
Moderator
Moderator
Posts: 927
Joined: Tue Jul 05, 2005 10:00 pm
Location: Cologne, Germany
Contact:

Re: Construct sqlcipher sqlite files for minimal.

Post by utelle » Sun Mar 08, 2020 8:27 am

dkaip wrote:
Sat Mar 07, 2020 5:09 pm
Suppose i have the code bellow ...

Code: Select all

wxSQLite3Database* initDB(void)
{
    wxString testDBName = wxS("dub.db");
    wxSQLite3Database* db = new wxSQLite3Database();
    db->Open(testDBName);
    if (!wxFileExists(testDBName))
    {
        db->UserAdd(wxS("user"), wxS("pswd"), true);
        db->UserLogin(wxS("user"), wxS("pswd"));
        db->ExecuteUpdate(wxS("CREATE TABLE texts (txt char(200))"));
        db->ExecuteUpdate(wxS("insert into texts values ('txt')"));
    }
    return db;
}
How i can take dub.db encrypted with any cipher type?
Well, sometimes it could help to read the documentation or to inspect the sample code.

If you are happy with the default encryption scheme (ChaCha20, if you didn't modify the build process), then simply call

Code: Select all

db->Open(dbFileName, passphrase);
to create or open an encrypted database file.

BTW, you have to check for the existence of the database file before calling the Open method, because the Open method creates the file.

If you want to use a specific non-default encryption cipher, you have to do it like this:

Code: Select all

wxSQLite3CipherSQLCipher sqlCipher4;
sqlCipher4.InitializeVersionDefault(4);
db->Open(dbFileName, sqlCipher4, passphrase);
You may adjust the cipher settings if necessary (see documentation of the cipher classes).

The following lines in your code only make sense if your application allows more than one user to access the same database, and you want to make sure that each user has to authenticate himself:

Code: Select all

        db->UserAdd(wxS("user"), wxS("pswd"), true);
        db->UserLogin(wxS("user"), wxS("pswd"));
This code has nothing to do with encryption. It is simply verified that the correct password for a certain user was given. See here for a detailed description of the user authentication module.

Post Reply