c#MD5加密类

本文介绍了一个名为kbMd5的类,该类提供了用于生成MD5哈希和进行MD5哈希验证的方法。通过使用MD5算法,可以将任意长度的输入转换为固定长度的128位哈希值,这在密码存储和数据完整性检查中非常有用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 1using System;
 2using System.Data;
 3using System.Configuration;
 4using System.Web;
 5using System.Web.Security;
 6using System.Web.UI;
 7using System.Web.UI.WebControls;
 8using System.Web.UI.WebControls.WebParts;
 9using System.Web.UI.HtmlControls;
10using System.Security.Cryptography;
11using System.Text;
12
13ExpandedBlockStart.gifContractedBlock.gif/**//// <summary>
14/// kbMd5 的摘要说明
15/// </summary>

16public class kbMd5
17ExpandedBlockStart.gifContractedBlock.gif{
18    public kbMd5()
19ExpandedSubBlockStart.gifContractedSubBlock.gif    {
20        //
21        // TODO: 在此处添加构造函数逻辑
22        //
23    }

24ContractedSubBlock.gifExpandedSubBlockStart.gif    MD5类的使用#region MD5类的使用
25ExpandedSubBlockStart.gifContractedSubBlock.gif    /**//// <summary>
26    /// 加密方法
27    /// </summary>
28    /// <param name="input">要转换的字符串</param>
29    /// <returns>转换后的MD5</returns>

30
31    public string GetMD5(string input)
32ExpandedSubBlockStart.gifContractedSubBlock.gif    {
33        MD5 md5 = MD5.Create();
34        string result = "";
35        byte[] data = md5.ComputeHash(Encoding.Default.GetBytes(input));
36        for (int i = 0; i < data.Length; i++)
37ExpandedSubBlockStart.gifContractedSubBlock.gif        {
38            result += data[i].ToString("x2");
39        }

40        return result;
41    }

42ExpandedSubBlockStart.gifContractedSubBlock.gif    /**//// <summary>
43    /// MD5比较
44    /// </summary>
45    /// <param name="input">输入的字符串</param>
46    /// <param name="data">比较的字符串</param>
47    /// <returns>是否相同</returns>
48    /// 

49    public bool passWordCheck(string input, string data)
50ExpandedSubBlockStart.gifContractedSubBlock.gif    {
51        string hashInput = GetMD5(input);
52        if (hashInput.Equals(data))
53ExpandedSubBlockStart.gifContractedSubBlock.gif        {
54            return true;
55        }

56        else
57ExpandedSubBlockStart.gifContractedSubBlock.gif        {
58            return false;
59        }

60    }

61    #endregion

62
63}

转载于:https://www.cnblogs.com/cm8448940/archive/2008/07/28/1254431.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值