Page 6 of 11
Re: SQLCipher ported to Harbour (Windows)
Posted: Wed Nov 06, 2013 9:21 pm
by esgici
dhaine_adp wrote:
...The problem is when I link libsqlcipher.a and lieay32.a the application looks for libeay32.dll...
Hi Dany
As far as know, when linked a lib<xxx>. a file to an application, this application shouldn't "look" a .dll file; unless you didn't use CallDLL32() function. An "a" extension implies a "static" library, and ".dll" means "dynamic"; does I know wrong
Regards
Re: SQLCipher ported to Harbour (Windows)
Posted: Wed Nov 06, 2013 10:56 pm
by dhaine_adp
Hi Esgici,
As far as know, when linked a lib<xxx>. a file to an application, this application shouldn't "look" a .dll file; unless you didn't use CallDLL32() function. An "a" extension implies a "static" library, and ".dll" means "dynamic"; does I know wrong
You're absolutely right and on the contrary I never made a call on libeay32.dll. I think it was called from libeay32.a which in turn used by libsqlcipher.a
There are sources from this old distribution site:
http://gnuwin32.sourceforge.net/packages/openssl.htm" onclick="window.open(this.href);return false;
But these sources are big and may require time to fully rebuilt the code for used with Hb/HMG. Definitely I will not take this path as much as possible.
I would like to encrypt the SQLite3 database and in doing so I found that libsqlcipher seems to be the best way but it requires to bundle the file libeay32.dll. Now this dll file is something that I wish to eliminate. I'd prefer to have an executable file without any dll file dependency.
Another option to try is to eliminate libsqlcipher totally and independently encrypt/decrypt the file attached to ON INIT procedure and modify the HMG error handler to encrypt the file before terminating the application. However this is less secure because if the application was terminated from the TaskManager, there is no guarantee that the database is still encrypted afterwards.
Regards,
Danny
Re: SQLCipher ported to Harbour (Windows)
Posted: Thu Nov 07, 2013 2:01 am
by danielmaximiliano
Danny :
utilize este HMG.HBC y reconstruya las librerias / Use this HMG.HBC and rebuild the libraries
Code: Select all
# paths
incpaths=/.
incpaths=include
libpaths=lib
# main hmg libs
libs=hmg
libs=crypt
libs=edit
libs=editex
libs=graph
libs=hfcl
libs=ini
libs=report
# system libs
libs=msvfw32
libs=vfw32
# harbour contrib libs
libs=hbct
libs=hbwin
libs=hbmzip
libs=minizip
libs=hbmemio
libs=hbmisc
libs=hbmysql
libs=mysql
libs=hbtip
libs=sqlite3
libs=hbsqlit3
libs=sddodbc
libs=rddsql
libs=sddmy
libs=hbodbc
libs=odbc32
libs=hbhpdf
libs=hbfimage
libs=hbpgsql
libs=hbnetio
libs=xhb
libs=png
libs=libhpdf
libs=hbvpdf
libs=hbzebra
# ***** include this lines *****
libs=hbssl
libs=libeay32
libs=ssleay32
Libs=hbtipssl
# ***** include this lines *****
# link compiled resources
sources=${hb_curdir}_temp.
extraiga los archivos y reemplaze / remove and replace files
- LIB.rar
- (900.61 KiB) Downloaded 324 times

- lib.png (87.82 KiB) Viewed 5230 times

- lib in IDE.png (25.97 KiB) Viewed 5230 times
I think this is what you need
Re: SQLCipher ported to Harbour (Windows)
Posted: Thu Nov 07, 2013 2:50 am
by Rathinagiri
Many of us (at least myself) don't like .dll files. However, using dll files is not a bad thing as it optimizes the memory usage. For example, if you use two programs calling the same functions, RAM usage is minimized as dll files are loaded only once.
Regarding this particular situation, I have tried to create static libraries of ssl, eay32 and ssleay32 but I couldn't. So, now I distribute my software along with dll files by a setup program. This setup program would copy the dll files in windows system folder, so that other programs (if any) which need these libraries can also be benefited. And, the user doesn't know about this.
Re: SQLCipher ported to Harbour (Windows)
Posted: Thu Nov 07, 2013 11:38 am
by danielmaximiliano
Hi Rathi :
Try this.
Download OpenSSL Win32 from
http://slproweb.com/download/Win32OpenS ... 1_0_1e.exe
Download OpenSSL Win64 from
http://slproweb.com/download/Win64OpenS ... 1_0_1e.exe
Install to c:\openssl
Download Harbour Contrib hbssl o use harbour sources in c:\harbour\core\contrib\hbssl
Execute
BuildOpenssl.bat and generate library

- lib static.png (59.01 KiB) Viewed 5207 times
Re: SQLCipher ported to Harbour (Windows)
Posted: Thu Nov 07, 2013 12:31 pm
by Rathinagiri
Thank you Daniel. I will try and tell you.

Re: SQLCipher ported to Harbour (Windows)
Posted: Thu Nov 07, 2013 7:48 pm
by dhaine_adp
Hi Daniel,
Thank you very much I'll try this. Linking the libsqlcipher gives me the error below if I don't include libeay32.dll.
I appreciate your help.
Regards,
Danny
Re: SQLCipher ported to Harbour (Windows)
Posted: Thu Nov 07, 2013 11:43 pm
by danielmaximiliano
Hi Rathinagiri :
in my settings your example SQLCipher works correctly
Code: Select all
#include <hmg.ch>
#define CRLF Chr(13)+Chr(10)
Function Main
local oDB := nil
local cKey := 'password123'
local cFile := 'sample.sqlite'
local aTable := {}
local cShow := ''
if file( cFile )
oDB := connect2db( 'sample.sqlite', .f. )
if oDB == Nil
msgstop( 'Database File can not be connected' )
else
iif( miscsql( oDB, 'pragma key = ' + c2sql( cKey ) ), ;
cShow += 'Encryption Key is set' + CRLF , msginfo( 'Encryption key can not be set' ) )
aTable := sql( oDB, 'select name, city from master' )
if len( aTable ) > 0
msginfo( 'Name:' + aTable[ 1, 1 ] + ' City:' + aTable[ 1, 2 ] )
endif
endif
else
oDB := connect2db( 'sample.sqlite', .t. )
if oDB == Nil
msgstop( 'Database File can not be connected' )
else
iif( miscsql( oDB, 'pragma key = ' + c2sql( cKey ) ) , ;
cShow += 'Encryption Key is set' + CRLF , msginfo( 'Encryption key can not be set!' ) )
iif( miscsql( oDB, 'create table master (name, city)' ) , ;
cShow += 'Master table is created successfully!' + CRLF , msginfo( 'Table can not be created!' ) )
iif( miscsql( oDB, 'insert into master ( name, city ) values ( ' + c2sql( 'Name1' ) + ', ' + c2sql( 'City1' ) + ' )' ) , ;
MsgInfo( cShow + 'Sample Data updated' , 'Good Notice' ) , msginfo( 'sample data can not be updated!' ) )
endif
endif
Return nil

- Sample.png (71.22 KiB) Viewed 5154 times
Re: SQLCipher ported to Harbour (Windows)
Posted: Fri Nov 08, 2013 6:10 pm
by dhaine_adp
Hi Rathi,
Any progress?

Somewhere in libsqlcipher is a call to libeay32.dll. It looks like we can't eliminate it and there is something interesting on sqlite3.c (libsqlcipher) at line no.: 4907-4918, it says:
#ifdef SQLITE_HAS_CODEC
/*
** Specify the key for an encrypted database. This routine should be
** called right after sqlite3_open().
**
** The code to implement this API is not available in the public release
** of SQLite.
*/
SQLITE_API int sqlite3_key(
sqlite3 *db, /* Database to be rekeyed */
const void *pKey, int nKey /* The key */
);
At this point, I am going to follow your lead, to distribute the libeay32.dll
@Daniel:
Perhaps you may have either of these files libeay32.dll or libeay64.dll or libeay.dll, into your system.
BTW my libeay32.dll is located not window system folder but from GetStartUpFolder(). During testing I'd just renaming it. I have a reason for not installing it on the system folder.
Well, I am not successful in embedding the libeay32.dll into the executable and what's left for me is to do a dirty hack out of it by combining the exe + dll file and at run-time write [fcreate()] the dll file somewhere or in the temp folder. But this method will surely irritate the Anti Virus software.
Attached is a hex view of an encrypted SQLite database.
Thanks,
Danny
Re: SQLCipher ported to Harbour (Windows)
Posted: Fri Nov 08, 2013 7:50 pm
by esgici
Hi Danny,
What Hex view prg you are using ?
Happy HMG'ing
