MD5哈佛德尔福2009 [英] MD5 Hashing in Delphi 2009

查看:216
本文介绍了MD5哈佛德尔福2009的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我使用wcrypt2脚本( http://pastebin.com/m2f015cfd



只需一个看看:



string:123456



哈希:



Delphi 7:e10adc3949ba59abbe56e057f20f883e - 真正的哈希。

Delphi 2007:e10adc3949ba59abbe56e057f20f883e - 真正的哈希也是。

And ...
Delphi 2009:5fa285e1bebe0a6623e33afc04a1fbd5 - WTF ??



我尝试过很多md5脚本,但是delphi 2009与所有脚本一样。任何帮助?谢谢。

解决方案

您的库不支持Unicode。只是传递一个AnsiString是不够的,因为它可能在内部使用字符串存储数据。



您可以尝试更新该库,等待作者更新它,或者仅使用Delphi 2009附带的 MessageDigest_5.pas 。它位于 source \Win32\soap\wsdlimporter 文件夹中,您将需要添加到您的路径,或明确地将其包含在您的项目中。



以下是在Delphi 2009中使用它的示例代码:

 使用Types,MessageDigest_5; 

procedure TForm16.Edit1Change(Sender:TObject);
var
MD5:IMD5;
begin
MD5:= GetMD5;
MD5.Init;
MD5.Update(TByteDynArray(RawByteString(Edit1.Text)),Length(Edit1.Text));
Edit2.Text:= LowerCase(MD5.AsString);
结束

而您正在营业:


MD5(123456)= e10adc3949ba59abbe56e057f20f883e


如果你想,你可以把它包装在一个简单的函数调用中。在转换为 TByteDynArray 之前,将其转换为 RawByteString 很重要,因为 RawByteString 转换将删除所有额外的Unicode字符。如果编辑包含Unicode字符,则可能会导致使用不良数据。



请记住, GetMD5 正在返回一个界面,因此是引用计数等。



圣诞快乐!


In borland delphi 7 and even in delphi 2007 everything worked, but in delphi 2009 it just returns the wrong hash!

I use wcrypt2 script (http://pastebin.com/m2f015cfd)

Just have a look:

string : "123456"

hash:

Delphi 7 : "e10adc3949ba59abbe56e057f20f883e" - real hash.
Delphi 2007 : "e10adc3949ba59abbe56e057f20f883e" - real hash too.
And... Delphi 2009 : "5fa285e1bebe0a6623e33afc04a1fbd5" - WTF??

I've tried a lot of md5 scripts, but delphi 2009 does the same with all of them. Any help? Thanks.

解决方案

Your library is not Unicode aware. Just passing it an AnsiString won't be enough because it probably uses strings internally to store data.

You could try to update that library, wait for the author to update it, or just use the MessageDigest_5.pas that ships with Delphi 2009. It is in the source\Win32\soap\wsdlimporter folder, which you will need to either add to your path, or explicitly include it in your project.

Here is some sample code using it in Delphi 2009:

uses Types, MessageDigest_5;

procedure TForm16.Edit1Change(Sender: TObject);
var
  MD5: IMD5;
begin
  MD5 := GetMD5;
  MD5.Init;
  MD5.Update(TByteDynArray(RawByteString(Edit1.Text)), Length(Edit1.Text));
  Edit2.Text := LowerCase(MD5.AsString);
end;

And you are in business:

MD5(123456) = e10adc3949ba59abbe56e057f20f883e

You could wrap it in a simple function call if you wanted to. It is important you cast to a RawByteString before casting to a TByteDynArray since the RawByteString cast drops all the extra Unicode characters. Granted if the edit contains Unicode characters then you could end up with bad data.

Keep in mind that GetMD5 is returning an interface, so it is reference counted, etc.

Merry Christmas!

这篇关于MD5哈佛德尔福2009的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆