用VB2005实现的ASP时代的MD5加密算法

算法实现很简单,改造已有的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;

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);
        }

    }

}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值