算法实现很简单,改造已有的vbscript代码就可以了
至于用处,也许可以为以前ASP程序遗留的数据作兼容,性能上面,当然不如.NET framework自带的性能高,不过 优化之后大致测试了一下,对于一个20长度的中文汉字加密需要时间大概在0.02秒左右
代码不好看,只提供类库下载
http://aspspider.net/daqingshu/urFiles/aspmd5.rar
使用方法很简单
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Security.Cryptography;
using System.Diagnostics;
using System.Text;
namespace wpDemo
...{
static class starter
...{
/**//// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
...{
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);
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);
Console.ReadLine();
}
static char[] hexDigits = ...{
'0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
public static string ToHexString(byte[] bytes)
...{
char[] chars = new char[bytes.Length * 2];
for (int i = 0; i < bytes.Length; i++)
...{
int b = bytes[i];
chars[i * 2] = hexDigits[b >> 4];
chars[i * 2 + 1] = hexDigits[b & 0xF];
}
return new string(chars);
}
}
}
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。