• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 8985
  • Last Modified:

MD5 Delphi XE2

Hi Guys,

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

Thanks in advance.
0
navidj
Asked:
navidj
  • 4
  • 3
  • 3
1 Solution
 
ThommyCommented:
You can use Indy (units IdHashMessageDigest and idHash)...
Calculate MD5 Checksum for a File or String from Delphi
0
 
ThommyCommented:
0
 
rinfoCommented:
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.

 
navidjAuthor Commented:
Thanks Rinfo,

I could use the units but I got this error:

 E2003 Undeclared identifier: 'TIdHash128'
0
 
rinfoCommented:
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
 
navidjAuthor Commented:
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
 
ThommyCommented:
It's probably removed in INDY 10!!!
How do I hash a string with Delphi?

I would recommend using Delphi Cryptography Package
0
 
rinfoCommented:
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
 
navidjAuthor Commented:
Thanks a lot guys

This is woring
0
 
navidjAuthor Commented:
Perfect solution
Thanks
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

  • 4
  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now