导航:
论坛 -> DELPHI技术
斑竹:liumazi,sephil
作者:
mj5423 (mj5423)
★☆☆☆☆
-
盒子活跃会员
2013/8/21 17:34:08
标题:
【求助】求帮忙把.Net的代码转换成Delphi的
浏览:1082
加入我的收藏
楼主:
代码如下: internal class MD5Method { // Methods public static string Encrypto(string str) { MD5 md = new MD5CryptoServiceProvider(); byte[] bytes = Encoding.Default.GetBytes(str); byte[] buffer2 = md.ComputeHash(bytes); string str2 = ""; for (int i = 0; i < buffer2.Length; i++) { str2 = str2 + buffer2[i].ToString("x").PadLeft(2, '0'); } return str2; } }
----------------------------------------------
-
作者:
mj5423 (mj5423)
★☆☆☆☆
-
盒子活跃会员
2013/8/21 17:45:25
1楼:
public virtual byte[] GetBytes(string s) { if (s == null) { throw new ArgumentNullException("s", Environment.GetResourceString("ArgumentNull_String")); } char[] chars = s.ToCharArray(); return this.GetBytes(chars, 0, chars.Length); } public byte[] ComputeHash(byte[] buffer) { if (this.m_bDisposed) { throw new ObjectDisposedException(null, Environment.GetResourceString("ObjectDisposed_Generic")); } if (buffer == null) { throw new ArgumentNullException("buffer"); } this.HashCore(buffer, 0, buffer.Length); this.HashValue = this.HashFinal(); byte[] buffer2 = (byte[]) this.HashValue.Clone(); this.Initialize(); return buffer2; }
----------------------------------------------
-
作者:
2013/8/22 8:03:19
2楼:
可以作成dll调用。
----------------------------------------------
Delphi爱好者。
作者:
2013/8/22 9:32:17
3楼:
第一个是 MD5 的输出。 你找个 MD5 单元就可以了。 用 INDY 也行。 type TMD5 = class(TIdHashMessageDigest5); function StrToMD5_UTF8(S: string): string; var Md5Encode: TMD5; begin Md5Encode:= TMD5.Create; try Result := Md5Encode.HashStringAsHex(S, TEncoding.UTF8); // Indy10中可以直接HashStringAsHex finally Md5Encode.Free; end; end;
----------------------------------------------
(C)(P)Flying Wang
作者:
2013/8/22 9:33:12
4楼:
你 第 2 个应该没啥用途。
----------------------------------------------
(C)(P)Flying Wang
作者:
mj5423 (mj5423)
★☆☆☆☆
-
盒子活跃会员
2013/8/22 10:02:45
5楼:
谢谢了,问题解决了 就是Md5,直接输出Md5就可以了
----------------------------------------------
-
作者:
2013/8/22 17:00:14
6楼:
一看 MD5Method 就知道是 MD5 了,我还以为你不知道去那里弄到 MD5 代码呢? 原来是不懂英文啊!
----------------------------------------------
(C)(P)Flying Wang