MelchaS
asked on
MD5 Encryption?
Hi,
I was wondering if there is a way to MD5 encrypt a string in delphi. Is there any component I could download? Or perhaps I'm missing something very obvious. I'm using Delphi 7.
Thanks,
- MelchaS
I was wondering if there is a way to MD5 encrypt a string in delphi. Is there any component I could download? Or perhaps I'm missing something very obvious. I'm using Delphi 7.
Thanks,
- MelchaS
Go to www.nevrona.com\Indy and download Indy Components. There's TIdCoderMD5.
ASKER
Err... What version? Because I have Indy, and there's no MD5 component...
in my D6 i've the 8.0.25 version. It's in Indy Misc Tab
Try Cryptlib from
http://www.cs.auckland.ac.nz/~pgut001/cryptlib/
The libraries and components support a range of security algorhythms including both two different MD5 format.
The libraries are cross-platform and cross language. The code is open source. There are Delphi specific interfaces/components for the libraries.
http://www.cs.auckland.ac.nz/~pgut001/cryptlib/
The libraries and components support a range of security algorhythms including both two different MD5 format.
The libraries are cross-platform and cross language. The code is open source. There are Delphi specific interfaces/components for the libraries.
ASKER
Do you know any other components for Delphi 7 ? I don't really want to get an older version of Indy/Delphi...
ASKER
ellesar: Thanks, I'll check that out
Another excellent exncryption library is DCP. Get it at:
http://www.cityinthesky.co.uk
It includes two examples which explain how to use the components. Besides MD4-5, it includes numerous hashes and ciphers (including the Rijndael encryption standard).
Kind regards,
Evarest
http://www.cityinthesky.co.uk
It includes two examples which explain how to use the components. Besides MD4-5, it includes numerous hashes and ciphers (including the Rijndael encryption standard).
Kind regards,
Evarest
MelchaS,
I found this code somewhere in my backup (We had used MD5 two years ago for an application).
It uses TIdHashMessageDigest5 and I could compile it in Delphi 7 prof.
Hope this helps,
...Shu
Here's the PAS:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, IdHash, IdHashMessageDigest, StdCtrls, Registry;
type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
Edit2: TEdit;
Memo1: TMemo;
Button2: TButton;
FlDlg: TOpenDialog;
Button3: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function rsReturnMD5(Value: TStream): PChar; stdcall;Overload;
Var
Digest: T4x4LongWordRecord;
S,
S1: String;
i: Integer;
begin
SetLength(S, 16);
with TIdHashMessageDigest5.Crea te do
begin
Digest := HashValue(Value);
Move(Digest, S[1], 16);
for i := 1 to Length(S) do begin
S1 := S1 + Format('%02x', [Byte(S[i])]);
end;
Result := PChar(S1);
Free;
end;
end;
function rsReturnMD5(Value: PChar): PChar; stdcall;Overload;
Var
Digest: T4x4LongWordRecord;
S,
S1: String;
i: Integer;
begin
SetLength(S, 16);
with TIdHashMessageDigest5.Crea te do
begin
Digest := HashValue(Value);
Move(Digest, S[1], 16);
for i := 1 to Length(S) do begin
S1 := S1 + Format('%02x', [Byte(S[i])]);
end;
Result := PChar(S1);
Free;
end;
end;
procedure TForm1.Button1Click(Sender : TObject);
Var
V1: String;
MyStream: TFileStream;
begin
If FlDlg.Execute Then
begin
MyStream := TFileStream.Create(FlDlg.F ileName, fmOpenRead);
V1 := rsReturnMD5(MyStream);
MyStream.Free;
ShowMessage(V1);
End
Else
ShowMessage('NotFound');
end;
procedure TForm1.Button2Click(Sender : TObject);
Var
V1,V2,V3: String;
begin
V1 := rsReturnMD5(PChar(edit1.Te xt));
V2 := rsReturnMD5(PChar(edit2.Te xt));
V3 := rsReturnMD5(PChar(Memo1.Te xt));
ShowMessage(V1+ #13#10 +V2+ #13#10 +V3);
end;
procedure TForm1.Button3Click(Sender : TObject);
Var
MyReg: TRegistry;
RegType : TRegDataType;
Buffer: array of byte;
CBuffer: array [0..5] of byte;
// Buffer: PByteArray;
lBinaryDataSize, i: Integer;
RegKey, RegValue, sValue, sData: String;
procedure MyProc(Var MyVar; MySz:Integer);
type
TBytes = array[0..MaxInt - 1] of Byte;
// Var
// DBuffer: TBytes;
begin
// DBuffer := TBytes(MyVar);
ShowMessage(IntToStr(TByte s(MyVar)[0 ]));
End;
begin
MyReg := TRegistry.Create;
MyReg.RootKey := HKEY_CURRENT_USER;
RegKey := 'Snehanshu';
sValue := 'BinVal';
RegValue := sValue;
MyReg.OpenKey(RegKey, False);
RegType := MyReg.GetDataType(RegValue );
if (RegType = rdString) or (RegType = rdExpandString) then sData := MyReg.ReadString(sValue);
if RegType = rdInteger then sData := IntToStr(MyReg.ReadInteger (sValue));
if RegType = rdBinary then
begin
lBinaryDataSize := MyReg.GetDataSize(sValue);
// Buffer := AllocMem(lBinaryDataSize);
SetLength(Buffer, lBinaryDataSize);
// MyReg.ReadBinaryData(RegVa lue, Buffer^, lBinaryDataSize);
MyReg.ReadBinaryData(RegVa lue, Buffer[0], lBinaryDataSize);
SValue := '';
For i := 0 to lBinaryDataSize-1 Do
SValue := SValue + IntToStr(Buffer[i])+',';
ShowMessage(SValue);
end;
TButton.CreateParented()
CBuffer[0] := 100;
MyProc(CBuffer,6);
MyReg.Free;
end;
end.
I found this code somewhere in my backup (We had used MD5 two years ago for an application).
It uses TIdHashMessageDigest5 and I could compile it in Delphi 7 prof.
Hope this helps,
...Shu
Here's the PAS:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, IdHash, IdHashMessageDigest, StdCtrls, Registry;
type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
Edit2: TEdit;
Memo1: TMemo;
Button2: TButton;
FlDlg: TOpenDialog;
Button3: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function rsReturnMD5(Value: TStream): PChar; stdcall;Overload;
Var
Digest: T4x4LongWordRecord;
S,
S1: String;
i: Integer;
begin
SetLength(S, 16);
with TIdHashMessageDigest5.Crea
begin
Digest := HashValue(Value);
Move(Digest, S[1], 16);
for i := 1 to Length(S) do begin
S1 := S1 + Format('%02x', [Byte(S[i])]);
end;
Result := PChar(S1);
Free;
end;
end;
function rsReturnMD5(Value: PChar): PChar; stdcall;Overload;
Var
Digest: T4x4LongWordRecord;
S,
S1: String;
i: Integer;
begin
SetLength(S, 16);
with TIdHashMessageDigest5.Crea
begin
Digest := HashValue(Value);
Move(Digest, S[1], 16);
for i := 1 to Length(S) do begin
S1 := S1 + Format('%02x', [Byte(S[i])]);
end;
Result := PChar(S1);
Free;
end;
end;
procedure TForm1.Button1Click(Sender
Var
V1: String;
MyStream: TFileStream;
begin
If FlDlg.Execute Then
begin
MyStream := TFileStream.Create(FlDlg.F
V1 := rsReturnMD5(MyStream);
MyStream.Free;
ShowMessage(V1);
End
Else
ShowMessage('NotFound');
end;
procedure TForm1.Button2Click(Sender
Var
V1,V2,V3: String;
begin
V1 := rsReturnMD5(PChar(edit1.Te
V2 := rsReturnMD5(PChar(edit2.Te
V3 := rsReturnMD5(PChar(Memo1.Te
ShowMessage(V1+ #13#10 +V2+ #13#10 +V3);
end;
procedure TForm1.Button3Click(Sender
Var
MyReg: TRegistry;
RegType : TRegDataType;
Buffer: array of byte;
CBuffer: array [0..5] of byte;
// Buffer: PByteArray;
lBinaryDataSize, i: Integer;
RegKey, RegValue, sValue, sData: String;
procedure MyProc(Var MyVar; MySz:Integer);
type
TBytes = array[0..MaxInt - 1] of Byte;
// Var
// DBuffer: TBytes;
begin
// DBuffer := TBytes(MyVar);
ShowMessage(IntToStr(TByte
End;
begin
MyReg := TRegistry.Create;
MyReg.RootKey := HKEY_CURRENT_USER;
RegKey := 'Snehanshu';
sValue := 'BinVal';
RegValue := sValue;
MyReg.OpenKey(RegKey, False);
RegType := MyReg.GetDataType(RegValue
if (RegType = rdString) or (RegType = rdExpandString) then sData := MyReg.ReadString(sValue);
if RegType = rdInteger then sData := IntToStr(MyReg.ReadInteger
if RegType = rdBinary then
begin
lBinaryDataSize := MyReg.GetDataSize(sValue);
// Buffer := AllocMem(lBinaryDataSize);
SetLength(Buffer, lBinaryDataSize);
// MyReg.ReadBinaryData(RegVa
MyReg.ReadBinaryData(RegVa
SValue := '';
For i := 0 to lBinaryDataSize-1 Do
SValue := SValue + IntToStr(Buffer[i])+',';
ShowMessage(SValue);
end;
TButton.CreateParented()
CBuffer[0] := 100;
MyProc(CBuffer,6);
MyReg.Free;
end;
end.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
BlackTigerX: Your component works best, thanks.