Blog
All Blog Posts | Next Post | Previous PostTEncryptedIniFile: easy to use class for handling app settings with encryption
Thursday, November 10, 2016
What's wrong with the KIS principle to store application settings in an INI file? The risk that someone is tampering with the INI file is an often heard reason for not using them. Not being able to store private or secret information another one.Both issues are solved with the introduced TEncryptedIniFile class. It descends from TMemIniFile and is as such a drop-in replacement and will deal only in app memory with decrypted data. In the file itself, the data is at all times encrypted. To build TEncryptedIniFile, we internally use AES 256bit encryption offered by the TAESEncryption class in TMS Cryptography Pack.
The code to use TEncryptedIniFile becomes something like:
const aeskey = 'anijd54dee1c3e87e1de1d6e4d4e1de3'; var mi: TEncryptedIniFile; begin try mi := TEncryptedIniFile.Create('.settings.cfg', aeskey); try FTPUserNameEdit.Text := mi.ReadString('FTP','USER',''); FTPPasswordNameEdit.Text := mi.ReadString('FTP','PWD',''); FTPPortSpin.Value := mi.ReadInteger('FTP','PORT',21); mi.WriteDateTime('SETTINGS','LASTUSE',Now); mi.UpdateFile; finally mi.Free; end; except ShowMessage('Error in encrypted file. Someone tampered with the file?'); end; end;
To start using this TEncryptedIniFile you can get the latest TMS Cryptography Pack that has this class now included.
Bruno Fierens
This blog post has received 6 comments.
2. Sunday, December 16, 2018 at 12:52:55 PM
Please use TEncryptedIniFile as included in the latest TMS Cryptography Pack with Delphi 10.3 Rio support. In this latest version, there is no issue with Delphi 10.3 Rio.
Bruno Fierens
3. Sunday, December 16, 2018 at 2:04:08 PM
Thank you for answer,
But i receive same error on same line:
type
TEncryptedIniFile = class(TMemInifile)
private
FFileName: string;
FEncoding: TEncoding;
FKey: string;
FOnDecryptError: TNotifyEvent;
procedure LoadValues;
public
constructor Create(const FileName: string; const Key: string); overload;
constructor Create(const FileName: string; const Encoding: TEncoding; CaseSensitive: Boolean); overload; override;<-- [dcc32 Error] inifiles_gen.pas(37): E2170 Cannot override a non-virtual method -->
procedure UpdateFile; override;
published
property OnDecryptError: TNotifyEvent read FOnDecryptError write FOnDecryptError;
end;
But i receive same error on same line:
type
TEncryptedIniFile = class(TMemInifile)
private
FFileName: string;
FEncoding: TEncoding;
FKey: string;
FOnDecryptError: TNotifyEvent;
procedure LoadValues;
public
constructor Create(const FileName: string; const Key: string); overload;
constructor Create(const FileName: string; const Encoding: TEncoding; CaseSensitive: Boolean); overload; override;<-- [dcc32 Error] inifiles_gen.pas(37): E2170 Cannot override a non-virtual method -->
procedure UpdateFile; override;
published
property OnDecryptError: TNotifyEvent read FOnDecryptError write FOnDecryptError;
end;
Gabriel Cristea
4. Monday, December 17, 2018 at 12:21:21 PM
Just fixed,
I dont have the last pack installed
After fix that all work correct
Thank you
I dont have the last pack installed
After fix that all work correct
Thank you
Cristea Gabriel
5. Friday, August 16, 2019 at 10:13:33 AM
Get error
Can''t find unit Inifiles
Can''t find unit Inifiles
Willie Holtzhauzen
6. Friday, August 16, 2019 at 10:18:42 AM
Verify the unit scope names in your project. These should normally be:
Winapi;System.Win;Data.Win;Datasnap.Win;Web.Win;Soap.Win;Xml.Win;Bde;System;Xml;Data;Datasnap;Web;Soap;Vcl;Vcl.Imaging;Vcl.Touch;Vcl.Samples;Vcl.Shell
Winapi;System.Win;Data.Win;Datasnap.Win;Web.Win;Soap.Win;Xml.Win;Bde;System;Xml;Data;Datasnap;Web;Soap;Vcl;Vcl.Imaging;Vcl.Touch;Vcl.Samples;Vcl.Shell
Bruno Fierens
All Blog Posts | Next Post | Previous Post
I have succesfully use your example in my project
But the problem appear starting with XE10.3 Rio, it get an error:
"[dcc32 Error] TMSEncryptedIniFile.pas(35): E2170 Cannot override a non-virtual method"
type
TEncryptedIniFile = class(TMemInifile)
private
FFileName: string;
FKey: string;
procedure LoadValues;
public
constructor Create(const FileName: string; const Key: string); overload;
constructor Create(const FileName: string; const Encoding: TEncoding; CaseSensitive: Boolean); overload; override; // <--This is the line with problem
procedure UpdateFile; override;
end;
I cannot manage to fix that.
Maybe you can help me, please ?
Thank you,
Gabriel Cristea
Gabriel Cristea