1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Donation with Paypal!!!

    Go to your paypal account and send directly donation to [email protected]

    1 month - 10 $ - Standart VIP

    6 months - 20 $- Standart VIP

    1 year - 30 $- Standart VIP

    2 years - 50 $- Standart VIP

    Gold member for life - 150 $- Standart VIP

    High Vip (Standart VIP include) group please send PM or email to [email protected] for info

    After Donation please send email to [email protected]

  3. Donation Ways 2020


    Paysend
  4. Telegram
Dismiss Notice

Donation with Paypal!!!

Go to your paypal account and send directly donation to [email protected]

1 month - 10 $ - Standart VIP

6 months - 20 $- Standart VIP

1 year - 30 $- Standart VIP

2 years - 50 $- Standart VIP

Gold member for life - 150 $- Standart VIP

High Vip (Standart VIP include) group please send PM or email to [email protected] for info

After Donation please send email to [email protected]

Dismiss Notice
For open hidden message no need write thanks, thank etc. Enough is click to like button on right side of thread.

MD5 Hash Strings, Streams, And Files In Delphi XE5

Discussion in 'Delphi Android And IOS' started by AdminDF, Mar 14, 2014.

  1. AdminDF
    Online

    AdminDFAdminDF is a Verified Member Delphifan Staff Member DF Staff

    If you are building any kind of login system or you need file signatures in Delphi XE5 Firemonkey you may be looking for an MD5 hash function. MD5 hash functionality ships with Delphi XE5 in the Indy component set. An MD5 hash is basically a string of unique characters that will represent the data you give it whether it is a password or an MP3 file. However, the code to access it is rather long which is where this library called hashutil comes in. The library should be cross platform and run on Windows, Android, IOS, and OSX. It provides some wrapper functions around the MD5 hash functionality which makes it easier to use. There is a function for a straight string, a stream, and a file. These three functions cover a lot of the usage and formats that you might need an MD5 hash for. You could for example get the MD5 hash for a list of MP3 files and use the hash as a fingerprint to see if there are duplicate files.. You could also create an MD5 hash of a password so that you are not storing the actual password in clear text. Here is a sample function:

    Code:
    function MD5(S: String): String;
    begin
    with TIdHashMessageDigest5.Create do
    begin
    Result := HashStringAsHex(S);
    DisposeOf;
    end;
    end;

    Until:
    Code:
    unit hashutil;
     
    interface
     
    uses SysUtils, Classes, IdGlobal, IdHash, IdHashMessageDigest, IdHashSHA, IdHashCRC;
     
    function MD5(S: String): String; overload;
    function MD5(S: TStream): String; overload;
    function MD5_Bytes(S: String): TIdBytes;
    function MD5_File(AFilename: String): String;
     
    implementation
     
     
    function MD5_File(AFilename: String): String;
    var
      fs: TFileStream;
    begin
      with TIdHashMessageDigest5.Create do
      begin
        fs := TFileStream.Create(AFilename, fmOpenRead);
        try
          Result := HashStreamAsHex(fs);
        finally
          fs.Free;
        end;
        Free;
      end;
    end;
     
    function MD5_Bytes(S: String): TIdBytes;
    begin
      with TIdHashMessageDigest5.Create do
      begin
        Result := HashString(S);
        Free;
      end;
    end;
     
    function MD5(S: String): String;
    begin
      with TIdHashMessageDigest5.Create do
      begin
        Result := HashStringAsHex(S);
        Free;
      end;
    end;
     
    function MD5(S: TStream): String;
    begin
      with TIdHashMessageDigest5.Create do
      begin
        Result := HashStreamAsHex(S);
        Free;
      end;
    end;
     
    end.
     
  2. martinflower
    Online

    martinflower Guest

    [font='Open Sans', Arial, Tahoma, Verdana, sans-serif]Thank[/font][font='Open Sans', Arial, Tahoma, Verdana, sans-serif] [/font][font='Open Sans', Arial, Tahoma, Verdana, sans-serif]you very much[/font][font='Open Sans', Arial, Tahoma, Verdana, sans-serif]![/font]
     

Share This Page