Topic: Encrypted INI content

Hello MVD Users
I need help to be able to Encrypt my INI content using EncrypyRC5.
I tried the following but I'm just getting question marks as the content. Any help?

ini.WriteString('Settings', 'Server', EncryptRC5(frmConnection.edServer.Text, 'zim'));

Thanks in advance

@thezimguy

Re: Encrypted INI content

Hello.


Please use TMemIniFile instead TIniFile, because TIniFile does not support unicode.

example:

procedure Form1_Button1_OnClick (Sender: TObject; var Cancel: boolean);
var
    MemIniFile: TMemIniFile;
    s: string;
begin
    MemIniFile := TMemIniFile.CreateUTF8( ExtractFilePath(Application.ExeName)+'test.ini' );
    MemIniFile.WriteString('main','ident', EncryptRC5('testtesttesttesttesttest','password'));

    s := MemIniFile.ReadString('main','ident', '');
    ShowMessage(s);
    s := DecryptRC5(s, 'password');
    ShowMessage(s);


    MemIniFile.UpdateFile;
    MemIniFile.Free;
end;
Dmitry.

Re: Encrypted INI content

Thank you so much boss
I followed your script and came out with the following but it only loads one textbox.
Any help would be appreciated

procedure frmConnection_OnShow(Sender: TObject; var Cancel: boolean; Action:String);
var MemIniFile: TMemIniFile;
begin
    MemIniFile := TMemIniFile.CreateUTF8(ExtractFilePath(Application.ExeName) + 'test.ini');
    frmConnection.edServer.Text := DecryptRC5(MemIniFile.ReadString('Settings', 'Server', ''), 'password');
    frmConnection.edPort.Text := DecryptRC5(MemIniFile.ReadString('Settings', 'Port', ''), 'password');
    frmConnection.edUsername.Text := DecryptRC5(MemIniFile.ReadString('Settings', 'Username', ''), 'password');
    frmConnection.edPassword.Text := DecryptRC5(MemIniFile.ReadString('Settings', 'Password', ''), 'password');
    frmConnection.edDatabase.Text := DecryptRC5(MemIniFile.ReadString('Settings', 'Database', ''), 'password');

    MemIniFile.UpdateFile;
    MemIniFile.Free;

end;

procedure Form1_Button1_OnClick (Sender: TObject; var Cancel: boolean);
var MemIniFile: TMemIniFile;
begin
    MemIniFile := TMemIniFile.CreateUTF8(ExtractFilePath(Application.ExeName) + 'test.ini');
    MemIniFile.WriteString('Settings', 'Server', EncryptRC5(frmConnection.edServer.Text, 'password'));
    MemIniFile.WriteString('Settings', 'Database', EncryptRC5(frmConnection.edDatabase.Text, 'password'));
    MemIniFile.WriteString('Settings', 'Port', EncryptRC5(frmConnection.edPort.Text, 'password'));
    MemIniFile.WriteString('Settings', 'Username', EncryptRC5(frmConnection.edUsername.Text, 'password'));
    MemIniFile.WriteString('Settings', 'Password', EncryptRC5(frmConnection.edPassword.Text, 'password'));

    ShowMessage('Settings saved successfully');
    MemIniFile.UpdateFile;
    MemIniFile.Free;
end;
@thezimguy

Re: Encrypted INI content

thezimguy
Please attach your project.

Dmitry.

Re: Encrypted INI content

Please find attached the project files.
Thank you in advance.

Post's attachments

Attachment icon ConnectionTest.zip 5.81 kb, 363 downloads since 2018-11-21 

@thezimguy

Re: Encrypted INI content

thezimguy wrote:

Please find attached the project files.
Thank you in advance.

Pls can I get a response to this post?
Thank you

@thezimguy

Re: Encrypted INI content

thezimguy wrote:

Thank you so much boss
I followed your script and came out with the following but it only loads one textbox.
Any help would be appreciated

procedure frmConnection_OnShow(Sender: TObject; var Cancel: boolean; Action:String);
var MemIniFile: TMemIniFile;
begin
    MemIniFile := TMemIniFile.CreateUTF8(ExtractFilePath(Application.ExeName) + 'test.ini');
    frmConnection.edServer.Text := DecryptRC5(MemIniFile.ReadString('Settings', 'Server', ''), 'password');
    frmConnection.edPort.Text := DecryptRC5(MemIniFile.ReadString('Settings', 'Port', ''), 'password');
    frmConnection.edUsername.Text := DecryptRC5(MemIniFile.ReadString('Settings', 'Username', ''), 'password');
    frmConnection.edPassword.Text := DecryptRC5(MemIniFile.ReadString('Settings', 'Password', ''), 'password');
    frmConnection.edDatabase.Text := DecryptRC5(MemIniFile.ReadString('Settings', 'Database', ''), 'password');

    MemIniFile.UpdateFile;
    MemIniFile.Free;

end;

procedure Form1_Button1_OnClick (Sender: TObject; var Cancel: boolean);
var MemIniFile: TMemIniFile;
begin
    MemIniFile := TMemIniFile.CreateUTF8(ExtractFilePath(Application.ExeName) + 'test.ini');
    MemIniFile.WriteString('Settings', 'Server', EncryptRC5(frmConnection.edServer.Text, 'password'));
    MemIniFile.WriteString('Settings', 'Database', EncryptRC5(frmConnection.edDatabase.Text, 'password'));
    MemIniFile.WriteString('Settings', 'Port', EncryptRC5(frmConnection.edPort.Text, 'password'));
    MemIniFile.WriteString('Settings', 'Username', EncryptRC5(frmConnection.edUsername.Text, 'password'));
    MemIniFile.WriteString('Settings', 'Password', EncryptRC5(frmConnection.edPassword.Text, 'password'));

    ShowMessage('Settings saved successfully');
    MemIniFile.UpdateFile;
    MemIniFile.Free;
end;

Without the EncryptRC5 and DecryptRC5 everything works fine.
Is that a bug?
Thanks
Still waiting for a response.

@thezimguy

Re: Encrypted INI content

Hello.


Sorry for delay.


I think there is some incompatibility between TMemIniFile and unicode symbols (UTF-16)
I have made some changes in the functions, please download latest version again:
http://myvisualdatabase.com/download/myvisualdb.exe

Dmitry.

Re: Encrypted INI content

DriveSoft wrote:

Hello.


Sorry for delay.


I think there is some incompatibility between TMemIniFile and unicode symbols (UTF-16)
I have made some changes in the functions, please download latest version again:
http://myvisualdatabase.com/download/myvisualdb.exe

Thank you
Very much appreciated

@thezimguy