?
Solved

MD5 Delphi XE2

Posted on 2012-04-12
10
Medium Priority
?
8,526 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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 900 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses
Course of the Month11 days, 1 hour left to enroll

770 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