Delphi FireDAC 下的 Sqlite(六) 加密

來源:互聯網
上載者:User

主要就是設定 TFDConnection 的兩個連結參數: Password, NewPassword, 非常簡單.

const  dbPath = 'C:\Temp\SQLiteTest.sdb';{建立加密資料庫, 密碼是 mm123}procedure TForm1.FormCreate(Sender: TObject);const  strTable = 'CREATE TABLE MyTable(Id integer, Name string(10), Age byte)'; //Id, Name, Age 三個欄位begin  if FileExists(dbPath) then DeleteFile(dbPath);  FDConnection1.Params.Add('DriverID=SQLite');  FDConnection1.Params.Add('Database=' + dbPath);  FDConnection1.Params.Add('Password=mm123'); //相同與 Password=aes-256:mm123; aes-256 是預設的密碼編譯演算法;  //還有: aes-128,aes-192,aes-256, aes-ctr-128,aes-ctr-192,aes-ctr-256, aes-ecb-128,aes-ecb-192,aes-ecb-256  //建表並輸入測試資料  FDConnection1.ExecSQL(strTable);  FDConnection1.ExecSQL('INSERT INTO MyTable(Id, Name, Age) VALUES(:1, :2, :3)', [1, 'abc', 23]);end;{開啟有密碼的資料庫}procedure TForm1.Button1Click(Sender: TObject);begin  FDConnection1.Params.Clear;  FDConnection1.Connected := False;  FDConnection1.Params.Add('DriverID=SQLite');  FDConnection1.Params.Add('Database=' + dbPath);  FDConnection1.Params.Add('Password=mm123');  FDConnection1.Connected := True;  FDQuery1.Open('SELECT * FROM MyTable');end;{修改密碼}procedure TForm1.Button2Click(Sender: TObject);begin  FDConnection1.Params.Clear;  FDConnection1.Connected := False;  FDConnection1.Params.Add('DriverID=SQLite');  FDConnection1.Params.Add('Database=' + dbPath);  FDConnection1.Params.Add('Password=mm123');  FDConnection1.Params.Add('NewPassword=mm12345'); //新密碼, 密碼為空白表示取消密碼  FDConnection1.Connected := True;  FDConnection1.Connected := False;end;

更多精彩內容:http://www.bianceng.cnhttp://www.bianceng.cn/Programming/Delphi/

FireDAC 還提供了一個專用的加密控制項 TFDSQLiteSecurity, 因為上面的方法足夠方便了, 所以用處不大.

FDSQLiteSecurity1.DriverLink := FDPhysSQLiteDriverLink1;  //TFDSQLiteSecurity 和 FireDAC.Phys.SQLite 裡的其他四個控制項, 使用前都要先指定這個屬性FDSQLiteSecurity1.Database := dbPath;    //指定資料庫路徑FDSQLiteSecurity1.Password := 'mm111';   //密碼FDSQLiteSecurity1.ToPassword := 'mm222'; //新密碼FDSQLiteSecurity1.SetPassword;           //設定密碼FDSQLiteSecurity1.ChangePassword;        //修改密碼FDSQLiteSecurity1.RemovePassword;        //移除密碼

協助裡面說: 通過 FireDAC 加密的 SQLite 與其它並不相容.

Author:cnblogs 萬一

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.