Solved

MD5 Delphi XE2

Posted on 2012-04-12
10
8,049 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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

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
 

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

838 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