Solved

MD5 Delphi XE2

Posted on 2012-04-12
10
7,691 Views
Last Modified: 2012-04-13
Hi Guys,

Whats the easiest way to have MD5 string conversion in a Delphi XE2 project.

Thanks in advance.
0
Comment
Question by:navidj
  • 4
  • 3
  • 3
10 Comments
 
LVL 19

Expert Comment

by:Thommy
ID: 37841268
You can use Indy (units IdHashMessageDigest and idHash)...
Calculate MD5 Checksum for a File or String from Delphi
0
 
LVL 19

Expert Comment

by:Thommy
ID: 37841271
0
 
LVL 9

Expert Comment

by:rinfo
ID: 37841850
use IdHashMessageDigest and idHash  from Indy.

function GetMD5from str(string:str)
begin
with TIdHashMessageDigest5.Create do
try
    Result := TIdHash128.AsHex(HashValue(str));
finally
    Free;
end;
0
 

Author Comment

by:navidj
ID: 37841915
Thanks Rinfo,

I could use the units but I got this error:

 E2003 Undeclared identifier: 'TIdHash128'
0
 
LVL 9

Expert Comment

by:rinfo
ID: 37841974
This is the entire code used by me

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs,IdHashMessageDigest,idHash, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
    function GetMD5fromstr(str1:String):String;
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);

begin
   showMessage(GetMd5fromstr('Hello'));
end;

function Tform1.GetMD5fromstr(str1:string) :String;
begin
with TIdHashMessageDigest5.Create do
try
    Result := TIdHash128.AsHex(HashValue(str1));
finally
    Free;
end;
end;

end.

Its working perfectly.
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 

Author Comment

by:navidj
ID: 37842015
Thanks again,

I think my Indy units are different they dont have TIdHash128 , please see the attachment.

do I need to instal any component?

Cheers
0
 
LVL 19

Expert Comment

by:Thommy
ID: 37842109
It's probably removed in INDY 10!!!
How do I hash a string with Delphi?

I would recommend using Delphi Cryptography Package
0
 
LVL 9

Accepted Solution

by:
rinfo earned 225 total points
ID: 37842183
For DelphiXE2
include these in uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, IdHashMessageDigest, IdGlobal;

and use this function
function GetMD5String (Str: String; ADestEncoding: TIdTextEncoding = nil): String;
    var MD5: TIdHashMessageDigest5;
    begin
          MD5: = TIdHashMessageDigest5.Create;
          try
          Result: = LowerCase (MD5.HashStringAsHex (Str, ADestEncoding));
          finally FreeAndNil (MD5);
    end;
    end;
0
 

Author Comment

by:navidj
ID: 37842238
Thanks a lot guys

This is woring
0
 

Author Closing Comment

by:navidj
ID: 37842244
Perfect solution
Thanks
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now