-
When i'm trying to encrypt existing database using aes128cbc, aes256cbc and rc4 it goes smooth. But when trying to use chacha20 and sqlcipher i'm getting It going this way. Am i missing something about chacha20 cipher?
|
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 2 replies
-
Unfortunately, the information you are giving is a bit unspecific. Which version of SQLite3 Multiple Ciphers are you using? Which are the exact steps to reproduce the problem?
Is the existing database a plain unencrypted database or an encrypted database? Are you using the SQLite3mc shell application to perform the encryption process? If not, which application are you using? Are you able to reproduce the problem using the SQLite3mc shell application?
I assume the format string In principle, the steps to encrypt a database with a certain cipher scheme and a certain passphrase are correct. Executing the following SQL pragmas will encrypt the database with cipher scheme chacha20 and passphrase passphrase: PRAGMA cipher='chacha20';
PRAGMA rekey='passphrase'; I verified this using the SQLite3mc shell application. It worked flawlessly for unencrypted as well as encrypted existing database files. Can you please show the exact sequence of SQL statements you used? |
Beta Was this translation helpful? Give feedback.
-
It seem to be indeed working via SQLite3mc shell.
It is indeed replaced with values, which turns into
or
etc This is Pascal. I'm trying both Free Pascal with SQLdb and Delphi with Zeos 8 + ZDbcSqLite. I didn't look into Zeos realization, but i guess it's more or less same. SQLdb is passing statement via sqlite3_prepare before executing. And |
Beta Was this translation helpful? Give feedback.
-
very short example of code program consoletest3;
{$mode objfpc}{$H+}
uses
{$IFDEF UNIX}
cthreads,
{$ENDIF}
Classes, SysUtils, SQLDB, SQLite3Conn, SQLDBLib;
var
LDBLink: TSQLite3Connection;
LDBTransaction: TSQLTransaction;
LDBLibrary: TSQLDBLibraryLoader;
sDatabaseName: String;
sCipher: String;
sKey: String;
sLibraryName: String;
begin
sDatabaseName := IncludeTrailingPathDelimiter(ExtractFilePath(ParamStr(0))) + 'test.s3db';
sCipher := 'chacha20';
//sCipher := 'aes256cbc';
sKey := '1234';
sLibraryName := 'sqlite3mc_icu.dll';
LDBLink := TSQLite3Connection.Create(Nil);
LDBTransaction := TSQLTransaction.Create(LDBLink);
LDBLink.Transaction := LDBTransaction;
LDBLink.DatabaseName := sDatabaseName;
LDBLibrary := TSQLDBLibraryLoader.Create(LDBLink);
LDBLibrary.ConnectionType := 'SQLite3';
LDBLibrary.LibraryName := sLibraryName;
LDBLibrary.LoadLibrary;
try
LDBLink.Open;
if not LDBLink.Connected then
raise Exception.Create('Cannot open database');
LDBLink.ExecuteDirect(Format('PRAGMA cipher="%s"', [sCipher]));
LDBLink.ExecuteDirect(Format('PRAGMA rekey="%s"', [sKey])); // <- error 1 in sqlite3_prepare if cipher is not aes256cbc, aes128cbc or rc4
LDBLink.Close;
finally
LDBLibrary.Free;
LDBTransaction.Free;
LDBLink.Free;
end;
end. |
Beta Was this translation helpful? Give feedback.
-
After a quick check of the SQLdb implementation I most likely found the cause of the problem. As far as I can tell the method This behaviour can be reproduced in the SQLite3mc shell: BEGIN; -- Start transaction
PRAGMA cipher='chacha20';
PRAGMA rekey='passphrase'; results in the message Unfortunately, the SQLdb package doesn't seem to offer a method to execute SQL statements without starting a transaction. However, creating a transaction object, setting its options to |
Beta Was this translation helpful? Give feedback.
-
Setting transaction to implicit did work. And with Zeos I was actually starting transaction. Commenting out lines did the trick. if ZConnection1.Connected then
begin
//ZConnection1.StartTransaction;
ZConnection1.ExecuteDirect(Format('PRAGMA cipher="%s"', [ComboBox1.Text]));
ZConnection1.ExecuteDirect(Format('PRAGMA rekey="%s"', [Edit1.Text])) ;
//ZConnection1.Commit;
end; Would really be great to denote it here for newbies |
Beta Was this translation helpful? Give feedback.
After a quick check of the SQLdb implementation I most likely found the cause of the problem. As far as I can tell the method
ExecuteDirect
starts internally a transaction. However,PRAGMA rekey
must not be enclosed in a transaction - it is simply mere chance that it works for some cipher schemes.This behaviour can be reproduced in the SQLite3mc shell:
results in the message
Parse error: SQL logic error
.Unfortunately, the SQLdb package doesn't seem to offer a method to execute SQL statements without starting a transaction. However, creating a transaction object, setting its options to
[stoUseImplicit]
, and …