Encrypting table field example at INSERT / UPADTE

Discussion of open issues, suggestions and bugs regarding IBDAC (InterBase Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
ataku
Posts: 1
Joined: Sun 18 Nov 2018 11:40

Encrypting table field example at INSERT / UPADTE

Post by ataku » Sun 18 Nov 2018 12:11

Hello,

Can anyone help me with an example of how to use IBCEncryptor at INSERT / UPADTE?

I tried this way, but the data in field 'NMN' left unencrypted after commit

Code: Select all

IBQuery1.Encryption.Encryptor := IBCEncryptor1;
IBQuery1.Encryption.Fields := 'NMN';
IBCEncryptor1.Password := '12345';

IBQuery1.SQL.Text := 'INSERT INTO T_NOM_5 (NUMBE,NMN) VALUES( :NUMBE, :NMN )';
IBQuery1.ParamByName('NUMBE').AsString := '1';
IBQuery1.ParamByName('NMN').AsString := 'text123';

IBQuery1.ExecSQL;
IBTransaction1.Commit;

Thank you

DELPHI2007
FB2.1
IBDAC6.1.7

ViktorV
Devart Team
Posts: 2496
Joined: Wed 30 Jul 2014 07:16

Re: Encrypting table field example at INSERT / UPADTE

Post by ViktorV » Wed 21 Nov 2018 14:26

In your sample you pass a value to the dataset parameter, but when using IBDAC Data Encryption you should pass a value to the dataset field. Currenlty, the parameters encryption in IBDAC Data Encryption is under development.
To change the encrypted field value in your sample, use the dataset methods Append .. Post, and as the TIBCQuery.SQL.Text SELECT value SELECT SQL query instead of INSERT. For example:

Code: Select all

IBQuery1.SQL.Text := 'SELECT NUMBE, NMN FROM T_NOM_5';
IBQuery1.Encryption.Encryptor := IBCEncryptor1;
IBQuery1.Encryption.Fields := 'NMN';
IBCEncryptor1.Password := '12345';
IBQuery1.SQL.DataTypeMap.AddFieldNameRule ('NMN', ftString);
IBQuery1.Open;
IBQuery1.Append;
IBQuery1.FieldByName('NUMBE').AsString := '1';
IBQuery1.FieldByName('NMN').AsString := 'text123';
IBQuery1.Post;

Post Reply