Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9160915
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T13:50:59+00:00 2026-06-17T13:50:59+00:00

I am looking for something more sophisticated than ROT13, but which does not require

  • 0

I am looking for something more sophisticated than ROT13, but which does not require a library (preferablly not even a unit, just a drop in function).

I want to symetrically encrypt/decrypt a given string with a password provided by the user. However, the result has to be a string, in the sense that it I have to be able to store it in an .INI file.

Does anyone have a simple function to do this (delphi XE2)? Google is not my friend today.

Thanks in advance


[Update] / [Bounty] Just to make it clear (aplogies if it was not so originally), I don’t want a hash. I have a list box where users can add/modiy/delete entries. I want to store those in an .INI file when the program closes and reload when it starts again. Anyone looking at the .INI file (for instance, opening it in Notepad) should not be able to read those strings.

I suppose that I could just stream the compnent as binary, but for eace of mind I would rather encrypt the strings using a user provided password. For the purpose of this applciation it does not matter if .INI file section names or keyte values are human readable, I just want to encrypt the data, giving me something list this when stored on disk:

[config]
numEntries=3

[listbox]
0=ywevdyuvewfcyuw
1=edw
2=hr4uifareiuf
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T13:51:01+00:00Added an answer on June 17, 2026 at 1:51 pm

    This is a replacement for Tinifile.
    ReadString and WriteString are overridden, these are internal used to for Read/WriteFloat, Read/WriteInteger etc.

    Strings are encrypted and stored as HEX-Strings.

    Demo usage:

    uses CryptingIni;
    {$R *.dfm}
    
    procedure TForm1.Button1Click(Sender: TObject);
    var
     ini:TCryptingIni;
    begin
        ini:=TCryptingIni.Create('C:\temp\test.ini');
        ini.UseInternalVersion(1234);
        ini.WriteFloat('Sect','Float',123.456);
        ini.WriteString('Sect2','String','How to encode');
        ini.Free;
    end;
    
    procedure TForm1.Button2Click(Sender: TObject);
    var
     ini:TCryptingIni;
    begin
        ini:=TCryptingIni.Create('C:\temp\test.ini');
        ini.UseInternalVersion(1234);
        Showmessage(FloatToStr(ini.ReadFloat('Sect','Float',0)));
        Showmessage(ini.ReadString('Sect2','String',''));
        Showmessage(ini.ReadString('SectUnkknow','Showdefault','DEFAULT'));
        ini.Free;
    end;
    

    You may use internal encryption method by UseInternalVersion, or provide own procedures with
    Procedure SetCryptingData(aEncryptProc, aDecryptProc: CryptingProc; aKey: Word);

    unit CryptingIni;
    
    // 2013 by Thomas Wassermann
    interface
    
    uses
      Windows, SysUtils, Variants, Classes, inifiles;
    
    type
    
      CryptingProc = Function(const InString: String; Key: Word): String;
    
      TCryptingIni = Class(TInifile)
        function ReadString(const Section, Ident, Default: string): string; override;
        procedure WriteString(const Section, Ident, Value: String); override;
      private
        FEncryptProc: CryptingProc;
        FDecryptProc: CryptingProc;
        FKey: Word;
      public
        Procedure SetCryptingData(aEncryptProc, aDecryptProc: CryptingProc; aKey: Word);
        Procedure UseInternalVersion(aKey: Word);
      End;
    
    implementation
    
    const
      c1 = 52845;
      c2 = 22719;
    
    Type
      TByteArray = Array [0 .. 0] of byte;
    
    Function AsHexString(p: Pointer; cnt: Integer): String;
    var
      i: Integer;
    begin
      Result := '';
      for i := 0 to cnt do
        Result := Result + '$' + IntToHex(TByteArray(p^)[i], 2);
    end;
    
    Procedure MoveHexString2Dest(Dest: Pointer; Const HS: String);
    var
      i: Integer;
    begin
      i := 1;
      while i < Length(HS) do
      begin
        TByteArray(Dest^)[i div 3] := StrToInt(Copy(HS, i, 3));
        i := i + 3;
      end;
    end;
    
    function EncryptV1(const s: string; Key: Word): string;
    var
      i: smallint;
      ResultStr: string;
      UCS: WIDEString;
    begin
      Result := s;
      if Length(s) > 0 then
      begin
        for i := 1 to (Length(s)) do
        begin
          Result[i] := Char(byte(s[i]) xor (Key shr 8));
          Key := (smallint(Result[i]) + Key) * c1 + c2
        end;
        UCS := Result;
        Result := AsHexString(@UCS[1], Length(UCS) * 2 - 1)
      end;
    end;
    
    function DecryptV1(const s: string; Key: Word): string;
    var
      i: smallint;
      sb: String;
      UCS: WIDEString;
    begin
      if Length(s) > 0 then
      begin
        SetLength(UCS, Length(s) div 3 div 2);
        MoveHexString2Dest(@UCS[1], s);
        sb := UCS;
        SetLength(Result, Length(sb));
        for i := 1 to (Length(sb)) do
        begin
          Result[i] := Char(byte(sb[i]) xor (Key shr 8));
          Key := (smallint(sb[i]) + Key) * c1 + c2
        end;
      end
      else
        Result := s;
    end;
    
    { TCryptingIni }
    
    function TCryptingIni.ReadString(const Section, Ident, Default: string): string;
    begin
      if Assigned(FEncryptProc) then
        Result := inherited ReadString(Section, Ident, FEncryptProc(Default, FKey))
      else
        Result := inherited ReadString(Section, Ident, Default);
      if Assigned(FDecryptProc) then
        Result := FDecryptProc(Result, FKey);
    end;
    
    procedure TCryptingIni.SetCryptingData(aEncryptProc, aDecryptProc: CryptingProc; aKey: Word);
    begin
      FEncryptProc := aEncryptProc;
      FDecryptProc := aDecryptProc;
      FKey := aKey;
    end;
    
    procedure TCryptingIni.UseInternalVersion(aKey: Word);
    begin
      FKey := aKey;
      FEncryptProc := EncryptV1;
      FDecryptProc := DecryptV1;
    end;
    
    procedure TCryptingIni.WriteString(const Section, Ident, Value: String);
    var
      s: String;
    begin
      if Assigned(FEncryptProc) then
        s := FEncryptProc(Value, FKey)
      else
        s := Value;
      inherited WriteString(Section, Ident, s);
    end;
    
    end.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Quick one; I know a solution, but I'm looking for something more elegant if
I’m looking for something exactly like: XMLTABLE, http://www.ibm.com/developerworks/data/library/techarticle/dm-0708nicola/ Does something like this exist in
I realize you can script Microsoft Office apps, but I'm looking for something more
I found this matrix for browser support: http://msdn.microsoft.com/en-us/library/ms251673.aspx . I'm looking for something more
I'm looking for something like the refactoring function in Eclipse but for copying files,
I'm looking for something current, iOS5 and Xcode 4.2. I'm not a fan of
I am looking for something similar to array_chunk() but using an empty value as
I am currently using jQuery validate.js, I am looking for something more advanced and
i'm looking for something more beautiful to do exactly what i'm doing over here.
I'm aware of the Microsoft.WindowsAzure.Diagnostics performance monitoring. I'm looking for something more real-time though

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.