64,644
社区成员
发帖
与我相关
我的任务
分享
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Security.Cryptography;
using System.Text;
/// <summary>
///MyHash 的摘要说明
/// </summary>
public class MyHash
{
public MyHash()
{
//
//TODO: 在此处添加构造函数逻辑
//
}
/// <summary>
/// SHA1加密方法
/// </summary>
/// <param name="old_string">原来的字符串作为参数传进来</param>
/// <returns>new_string返回加密后的新字符串(长度是40位)</returns>
public static string SHA1_Hash(string old_string)
{
SHA1 sha1 = new SHA1CryptoServiceProvider();
byte[] bytes_old_string = UTF8Encoding.Default.GetBytes(old_string);
byte[] bytes_new_string = sha1.ComputeHash(bytes_old_string);
string new_string = BitConverter.ToString(bytes_new_string);
new_string = new_string.Replace("-", "").ToUpper();
return new_string;
}
/// <summary>
/// MD5加密方法
/// </summary>
/// <param name="old_string">原来的字符串作为参数传进来</param>
/// <returns>new_string返回加密后的新字符串(长度是32位)</returns>
public static string MD5_Hash(string old_string)
{
MD5 md5 = new MD5CryptoServiceProvider();
byte[] bytes_old_string = UTF8Encoding.Default.GetBytes(old_string);
byte[] bytes_new_string = md5.ComputeHash(bytes_old_string);
string new_string = BitConverter.ToString(bytes_new_string);
new_string = new_string.Replace("-","").ToUpper();
return new_string;
}
}