Solved

MD5 Delphi XE2

Posted on 2012-04-12
10
8,229 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

739 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