現(xiàn)在制作的web系統(tǒng)需要用到加密
依舊選擇md5吧(其實(shí)我也就用過md5^_^) 找到了兩種實(shí)現(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ù)進(jìn)行加密 第二種直接加密以string類型作為參數(shù),這個(gè)直觀些 不懂兩個(gè)加密的結(jié)果怎么樣?? TextBox1.Text = MD51("12345"); TextBox2.Text = MD52("12345", 32); 分別是md51:gnzLDuqKcGxMNKFokfhOew== md52:827ccb0eea8a706c4c34a16891f84e7b why?不一樣,用我的直覺判斷第二個(gè)是我經(jīng)常見到的md5加密 而第一種方式就搞不懂了呵呵 提示一下 第二種方式使用.ToLower()是為了與asp中的md5加密兼容; 與asp兼容還有就是加密中文可能會(huì)遇到編碼問題。 |
|