FireDAC under Sqlite [6] - Encryption.

The main link is to set two parameters of TFDConnection: Password, NewPassword, very simple.


 

const 
  dbPath = 'C: \ the Temp \ SQLiteTest.sdb' ; {establish an encrypted database, password} mm123 Procedure TForm1.FormCreate (Sender: TObject);
 const 
  strTable = 'the MyTable the CREATE TABLE (Id Integer, the Name String (10), byte Age) ' ; // Id, the Name, Age three field the begin IF the FileExists (dbPath) the then the DeleteFile (dbPath);
  FDConnection1.Params.Add ( ' the SQLite DriverID = ' );
  FDConnection1.Params.Add ( ' Database = ' dbPath +);
  FDConnection1.Params.Add ( 'Password = mm123' ); // same Password = aes-256: mm123; aes-256 is the default encryption algorithm;




  

                                              // There: aes-128, aes-192 , aes-256, aes-ctr-128, aes-ctr-192, aes-ctr-256, aes-ecb-128, aes-ecb-192, aes-ecb -256 
  // build table and input test data 
  FDConnection1.ExecSQL (strTable); 
  FDConnection1.ExecSQL ( 'the INSERT the INTO the MyTable (Id, the Name, Age) the VALUES (:. 1,: 2,:. 3)' , [ . 1 , 'ABC ' , 23 is ]);
 End ; {open a password database} Procedure TForm1.Button1Click (Sender: TObject);
 the begin 
  FDConnection1.Params.Clear; 
  FDConnection1.Connected: = False; 
  FDConnection1.Params.Add ( ' = DriverID the 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;


FireDAC also provides a dedicated encryption controls TFDSQLiteSecurity, since the above method easy enough, so little use.


FDSQLiteSecurity1.DriverLink: = FDPhysSQLiteDriverLink1;   // TFDSQLiteSecurity and FireDAC.Phys.SQLite in four other controls, they have to specify that you want to use this property 
FDSQLiteSecurity1.Database: = dbPath;     // specify the database path 
FDSQLiteSecurity1.Password: = 'mm111 '// password 
FDSQLiteSecurity1.ToPassword: = ' mm222 ' ; // new password 
FDSQLiteSecurity1.SetPassword;            // set password 
FDSQLiteSecurity1.ChangePassword;         // change the password 
FDSQLiteSecurity1.RemovePassword;         // remove the password


Help which said: by FireDAC encrypted SQLite is not compatible with the other.

Guess you like

Origin www.cnblogs.com/yjhb/p/11804229.html