久草最新视频-久草最新网址-久国产-久国产视频-天天插夜夜操-天天插一插

北大青鳥總結:ASP.NET中的加密方法介紹(二)

接上文,北京北大青鳥學校在上一篇文章中介紹了MD5和SHA1的定義。這篇文章中我們將介紹加密的方法。
 
我們平常用的最多的無非就是加密用戶密碼,把加密好的密碼存儲到數據庫中,進行密碼比較的時候,把用戶輸入的密碼再進行加密,然后與數據庫中的密文進行比較。
 
下面,北京北大青鳥學校為大家舉一個例子:

以MD5為例(SHA1大致相同,只是使用的類不一樣)
MD5 相關類:
System.Security.Cryptography.MD5

System.Security.Cryptography.MD5CryptoServiceProvider()

System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(strSource, MD5)

SHA1相關類:
System.Security.Cryptography.SHA1

System.Security.Cryptography.SHA1CryptoServiceProvider()

System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(strSource, SHA1)

方法如下:(用的vs2005)
1/**////
2 /// 方法一:通過使用 new 運算符創建對象
3 ///
4 /// 需要加密的明文
5 /// 返回16位加密結果,該結果取32位加密結果的第9位到25位
6 public string Get_MD5_Method1(string strSource)
7 {
8 //new
9  System.Security.Cryptography.MD5 md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
10
11  //獲取密文字節數組
12  byte[] bytResult = md5.ComputeHash(System.Text.Encoding.Default.GetBytes(strSource));
13
14  //轉換成字符串,并取9到25位
15  string strResult = BitConverter.ToString(bytResult, 4, 8);
16  //轉換成字符串,32位
17  //string strResult = BitConverter.ToString(bytResult);
18
19  //BitConverter轉換出來的字符串會在每個字符中間產生一個分隔符,需要去除掉
20  strResult = strResult.Replace(-, );
21  return strResult;
22 }
23
24 /**//// (北京北大青鳥學校)
25 /// 方法二:通過調用特定加密算法的抽象類上的 Create 方法,創建實現特定加密算法的對象。
26 ///
27 /// 需要加密的明文
28 /// 返回32位加密結果
29 public string Get_MD5_Method2(string strSource)
30 {
31  string strResult = ;
32
33  //Create
34  System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create();
35
36  //注意編碼UTF8、UTF7、Unicode等的選擇
37  byte[] bytResult = md5.ComputeHash(System.Text.Encoding.UTF8.GetBytes(strSource));
38
39  //字節類型的數組轉換為字符串
40  for (int i = 0; i < bytResult.Length; i++)
41  {
42   //16進制轉換
43   strResult = strResult + bytResult[i].ToString(X);
44  }
45  return strResult;
46 }
47
48 /**//// (北京北大青鳥學校)
49 /// 方法三:直接使用HashPasswordForStoringInConfigFile生成
50 ///
51 /// 需要加密的明文
52 /// 返回32位加密結果
53 public string Get_MD5_Method3(string strSource)
54 {
55  return System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(strSource, MD5);
56 }
 
北京北大青鳥學校介紹,這些加密函數都是在服務器端執行,也就是說,當用戶輸入密碼后,從客戶端到服務器端傳輸時,用戶的密碼沒有任何保護,很危險。銀行的做法是在客戶端安裝ActiveX控件,在客戶端就把一些重要信息進行加密,再發送。
 

北大青鳥網上報名
北大青鳥招生簡章
主站蜘蛛池模板: 青草视频网站在线观看 | 青青在线视频观看 | 激情综合久久 | 亚洲成网站 | 国产va免费高清在线观看 | 日韩欧美在线观看一区 | 国产精品高清在线观看 | 曰韩高清一级毛片 | 成人网影| 亚洲男人天堂视频 | 欧美成人性生活视频 | 好男人影视www | 天堂网2016| 免费国产怡红院在线观看 | 亚洲 武侠 欧美 自拍 校园 | 久久99国产这里有精品视 | 亚州免费视频 | 老司机精品视频在线 | 91视频免费视频 | 少妇高潮太爽了在线视频 | 哦好紧 | 日本夜夜操 | 手机看片午夜 | 精品久久久久中文字幕日本 | 一区高清 | 啦啦啦在线观看免费观看4 啦啦啦手机在线播放视频 啦啦啦视频在线视频免费4 | 久久精品这里只有精品 | www.91免费视频| 亚洲福利视频一区二区三区 | 9966国产精品视频 | 精品视频69v精品视频 | 国产片入口 | 岛国在线播放v片免费 | 91视频啪啪 | 高清国产亚洲va精品 | 在线天堂在线 | 78m成年视频免费观看 | 亚洲性大片| 日韩观看 | 75伊人| 天天艹逼 |