本篇文章給大家分享的是有關(guān)如何在asp.net項(xiàng)目中實(shí)現(xiàn)一個(gè)md5加密功能,小編覺得挺實(shí)用的,因此分享給大家學(xué)習(xí),希望大家閱讀完這篇文章后可以有所收獲,話不多說,跟著小編一起來看看吧。
代碼如下:
///
/// MD5加密
///
/// 需要加密的明文
///
public static string Get_MD5(string strSource, string sEncode)
{
//new
System.Security.Cryptography.MD5 md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
//獲取密文字節(jié)數(shù)組
byte[] bytResult = md5.ComputeHash(System.Text.Encoding.GetEncoding(sEncode).GetBytes(strSource));
//轉(zhuǎn)換成字符串,并取9到25位
//string strResult = BitConverter.ToString(bytResult, 4, 8);
//轉(zhuǎn)換成字符串,32位
string strResult = BitConverter.ToString(bytResult);
//BitConverter轉(zhuǎn)換出來的字符串會(huì)在每個(gè)字符中間產(chǎn)生一個(gè)分隔符,需要去除掉
strResult = strResult.Replace("-", "");
return strResult.ToLower();
}
以上就是如何在asp.net項(xiàng)目中實(shí)現(xiàn)一個(gè)md5加密功能,小編相信有部分知識點(diǎn)可能是我們?nèi)粘9ぷ鲿?huì)見到或用到的。希望你能通過這篇文章學(xué)到更多知識。更多詳情敬請關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。