Assume that we want to attach an encrypted (with UniDAC) database.
Code: Select all
UniConnection1.ExecSQL('attach "encrypted_sqlite.db" as source');
Is it possible, or is it not possible to do that?
Thanks.
Code: Select all
UniConnection1.ExecSQL('attach "encrypted_sqlite.db" as source');
Code: Select all
ATTACH DATABASE 'file2.db' AS two KEY 'xyzzy';
Code: Select all
const
MyKEY : array of char = [#00, #01, #02, #03, #04, #05, #06, #07];
begin
UniConnection1.ExecSQL('attach database 'file2.db' as two KEY ' + QuotedStr(String(MyKEY)));
end;
Code: Select all
const
Key2564 : Array of Char = [#10, #101, #12, #103, #145, #150, #110, #109,
#188, #129, #67, #152, #100, #141, #187, #135,
#01, #11, #12, #31, #10, #17, #62, #78,
#11, #9, #02, #240, #230, #170, #206, #172,
#188, #127, #207, #113, #44, #77, #11, #15,
#182, #193, #102, #109, #170, #127, #188, #195];
Code: Select all
program Project4;
{$APPTYPE CONSOLE}
{$R *.res}
uses
SysUtils,
Uni,
SQLiteUniProvider,
LiteError;
const
KeyBytes: TBytes = [10, 101, 12, 103, 145, 150, 110, 109,
188, 129, 67, 152, 100, 141, 187, 135,
01, 11, 12, 31, 10, 17, 62, 78,
11, 9, 02, 240, 230, 170, 206, 172,
188, 127, 207, 113, 44, 77, 11, 15,
182, 193, 102, 109, 170, 127, 188, 195];
var
UniConnection: TUniConnection;
i, ii: integer;
str_key: AnsiString;
hex_key: string;
NewBytes: TBytes;
begin
try
str_key := TEncoding.ANSI.GetString(KeyBytes);
hex_key := '';
NewBytes := TEncoding.Convert(TEncoding.ANSI, TEncoding.UTF8, KeyBytes);
for i := 0 to High(NewBytes) do
hex_key := hex_key + IntToHex(NewBytes[i], 2);
if FileExists('d:\main.db3') then
DeleteFile('d:\main.db3');
if FileExists('d:\attached.db3') then
DeleteFile('d:\attached.db3');
UniConnection := TUniConnection.Create(nil);
try
UniConnection.ProviderName := 'SQLite';
UniConnection.Database := 'd:\main.db3';
UniConnection.SpecificOptions.Values['Direct'] := 'True';
UniConnection.SpecificOptions.Values['ForceCreateDatabase'] := 'true';
UniConnection.Connect;
UniConnection.ExecSQL('create table table1(id integer primary key, txt varchar(100))');
UniConnection.ExecSQL('insert into table1(id, txt) values(1, ''test'')');
UniConnection.Disconnect;
UniConnection.Database := 'd:\attached.db3';
UniConnection.SpecificOptions.Values['EncryptionKey'] := str_key;
UniConnection.SpecificOptions.Values['EncryptionAlgorithm'] := 'leAES128';
UniConnection.Connect;
UniConnection.ExecSQL('create table table2(id integer primary key, txt varchar(100))');
UniConnection.Disconnect;
UniConnection.Database := 'd:\main.db3';
UniConnection.SpecificOptions.Values['EncryptionKey'] := '';
UniConnection.SpecificOptions.Values['EncryptionAlgorithm'] := 'leDefault';
UniConnection.Connect;
try
UniConnection.ExecSQL('PRAGMA encryption=AES128');
UniConnection.ExecSQL('ATTACH DATABASE ''d:\attached.db3'' AS two KEY X''' + hex_key + '''');
except
on E: ESQLiteError do
Writeln(e.Message + ' ' + E.ErrorCode.ToString);
end;
UniConnection.ExecSQL('insert into two.table2 select * from main.table1');
UniConnection.ExecSQL('select * from two.table2');
finally
UniConnection.Free;
end;
except
on E: Exception do
writeln(e.Message);
end;
readln;
end.