2020国产成人精品视频,性做久久久久久久久,亚洲国产成人久久综合一区,亚洲影院天堂中文av色

分享

asp.net編程中實現(xiàn) MD5 加密

 悟靜 2011-09-29
現(xiàn)在制作的web系統(tǒng)需要用到加密
依舊選擇md5吧(其實我也就用過md5^_^)

找到了兩種實現(xiàn)



/**////
/// 用md5加密
///

/// 輸入的數(shù)據(jù)
///
public static string MD5(string Sourcein)
...{
MD5CryptoServiceProvider MD5CSP = new MD5CryptoServiceProvider();
byte[] MD5Source = System.Text.Encoding.UTF8.GetBytes(Sourcein);
byte[] MD5Out = MD5CSP.ComputeHash(MD5Source);
return Convert.ToBase64String(MD5Out);
}

public static string md5(string str, int code)
...{
if (code == 16) //16位MD5加密(取32位加密的9~25字符)
...{
return System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(str, "MD5").ToLower().Substring(8, 16);
}

if (code == 32) //32位加密
...{
return System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(str, "MD5").ToLower();
}
return "00000000000000000000000000000000";
}


現(xiàn)在有兩種方法,第一種是通過MD5CryptoServiceProvider類對字節(jié)數(shù)據(jù)進行加密

第二種直接加密以string類型作為參數(shù),這個直觀些

不懂兩個加密的結(jié)果怎么樣??

TextBox1.Text = MD51("12345");
TextBox2.Text = MD52("12345", 32);

分別是md51:gnzLDuqKcGxMNKFokfhOew==

md52:827ccb0eea8a706c4c34a16891f84e7b

why?不一樣,用我的直覺判斷第二個是我經(jīng)常見到的md5加密

而第一種方式就搞不懂了呵呵

提示一下

第二種方式使用.ToLower()是為了與asp中的md5加密兼容;

與asp兼容還有就是加密中文可能會遇到編碼問題。

    本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
    轉(zhuǎn)藏 分享 獻花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多