算法实现很简单,改造已有的vbscript代码就可以了
至于用处,也许可以为以前ASP程序遗留的数据作兼容,性能上面,当然不如.NET framework自带的性能高,不过 优化之后大致测试了一下,对于一个20长度的中文汉字加密需要时间大概在0.02秒左右
代码不好看,只提供类库下载
http://www.cnblogs.com/Files/daqingshu/ASPMD5.rar
空间没有了
使用方法很简单
using
System;
using
System.Collections.Generic;
using
System.Windows.Forms;
using
System.Security.Cryptography;
using
System.Diagnostics;
using
System.Text;
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
namespace
wpDemo
![](https://i-blog.csdnimg.cn/blog_migrate/a41954a27d6ad96fa2c2cf816e677448.gif)
...
{
static class starter
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
/**//// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Generic.Algorithms.ASPMD5 md5 = new Generic.Algorithms.ASPMD5();
string strPassword = "中国中国中国中国中国中国中国中国中国中国";
Stopwatch horse = new Stopwatch();
horse.Start();
string a = md5.MD5(strPassword, 32);
horse.Stop();
Console.WriteLine(horse.Elapsed.ToString());
Console.WriteLine(a);
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
MD5CryptoServiceProvider hashmd5;
hashmd5 = new MD5CryptoServiceProvider();
horse.Reset();
horse.Start();
byte[] md5arr = hashmd5.ComputeHash(Encoding.Default.GetBytes(strPassword));
string b = BitConverter.ToString(md5arr).Replace("-", "").ToLower();
horse.Stop();
Console.WriteLine(horse.Elapsed.ToString());
Console.WriteLine(b);
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
Console.ReadLine();
}
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
static char[] hexDigits = ...{
'0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
public static string ToHexString(byte[] bytes)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
char[] chars = new char[bytes.Length * 2];
for (int i = 0; i < bytes.Length; i++)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
int b = bytes[i];
chars[i * 2] = hexDigits[b >> 4];
chars[i * 2 + 1] = hexDigits[b & 0xF];
}
return new string(chars);
}
}
}