日本好好热aⅴ|国产99视频精品免费观看|日本成人aV在线|久热香蕉国产在线

  • <cite id="ikgdy"><table id="ikgdy"></table></cite>
    1. 西西軟件園多重安全檢測下載網(wǎng)站、值得信賴的軟件下載站!
      軟件
      軟件
      文章
      搜索

      首頁編程開發(fā)C#.NET → C#實現(xiàn)DES加密算法與DES解密代碼

      C#實現(xiàn)DES加密算法與DES解密代碼

      相關(guān)軟件相關(guān)文章發(fā)表評論 來源:本站整理時間:2010/11/23 9:44:25字體大。A-A+

      作者:佚名點擊:673次評論:0次標(biāo)簽: DES加密算法 DES

      • 類型:圖像瀏覽大。13.0M語言:英文 評分:3.6
      • 標(biāo)簽:
      立即下載
      DES ( data encryption Standard) 是一種世界標(biāo)準(zhǔn)的加密形式, 已15 年歷史了,雖然有些老, 可還算是比較可靠的算法。在七十的初期, 隨著計算機(jī)之間的通信發(fā)展, 需要有一種標(biāo)準(zhǔn)密碼算法為了限制不同算法的激增使他們之間不能互相對話。為解決這個問題, 美國國家安全局(N.S.A ) 進(jìn)行招標(biāo)。 I.B.M 公司研發(fā)了一種算法, 稱為:Lucifer。 經(jīng)過幾年的研討和修改, 這種算法, 成為了今天的D.E.S,1976 年11月23 日, 終于被美國國家安全局采用。 

       
      ///<summary>
         
      /// DES加密與解密
         
      ///</summary>
          publicclass DESEncrypt
          {

             
      #region DES加密

             
      ///<summary>
             
      /// 使用默認(rèn)密鑰加密
             
      ///</summary>
             
      ///<param name="strText"></param>
             
      ///<returns></returns>
              publicstaticstring Encrypt(string strText)
              {
                 
      return Encrypt(strText, "TSF");
              }

             
      ///<summary>
             
      /// 使用給定密鑰加密
             
      ///</summary>
             
      ///<param name="strText"></param>
             
      ///<param name="sKey">密鑰</param>
             
      ///<returns></returns>
              publicstaticstring Encrypt(string strText, string sKey)
              {
                  DESCryptoServiceProvider des
      =new DESCryptoServiceProvider();
                 
      byte[] inputByteArray = Encoding.Default.GetBytes(strText);
                  des.Key
      = ASCIIEncoding.ASCII.GetBytes(System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(sKey, "md5").Substring(0, 8));
                  des.IV
      = ASCIIEncoding.ASCII.GetBytes(System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(sKey, "md5").Substring(0, 8));
                  System.IO.MemoryStream ms
      =new System.IO.MemoryStream();
                  CryptoStream cs
      =new CryptoStream(ms, des.CreateEncryptor(), CryptoStreamMode.Write);
                  cs.Write(inputByteArray,
      0, inputByteArray.Length);
                  cs.FlushFinalBlock();
                  StringBuilder ret
      =new StringBuilder();
                 
      foreach (byte b in ms.ToArray())
                  {
                      ret.AppendFormat(
      "{0:X2}", b);
                  }
                 
      return ret.ToString();
              }

             
      #endregion

             
      #region DES解密

             
      ///<summary>
             
      /// 使用默認(rèn)密鑰解密
             
      ///</summary>
             
      ///<param name="strText"></param>
             
      ///<returns></returns>
              publicstaticstring Decrypt(string strText)
              {
                 
      return Decrypt(strText, "TSF");
              }

             
      ///<summary>
             
      /// 使用給定密鑰解密
             
      ///</summary>
             
      ///<param name="strText"></param>
             
      ///<param name="sKey"></param>
             
      ///<returns></returns>
              publicstaticstring Decrypt(string strText, string sKey)
              {
                  DESCryptoServiceProvider des
      =new DESCryptoServiceProvider();
                 
      int len = strText.Length /2;
                 
      byte[] inputByteArray =newbyte[len];
                 
      int x, i;
                 
      for (x =0; x < len; x++)
                  {
                      i
      = Convert.ToInt32(strText.Substring(x *2, 2), 16);
                      inputByteArray[x]
      = (byte)i;
                  }
                  des.Key
      = ASCIIEncoding.ASCII.GetBytes(System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(sKey, "md5").Substring(0, 8));
                  des.IV
      = ASCIIEncoding.ASCII.GetBytes(System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(sKey, "md5").Substring(0, 8));
                  System.IO.MemoryStream ms
      =new System.IO.MemoryStream();
                  CryptoStream cs
      =new CryptoStream(ms, des.CreateDecryptor(), CryptoStreamMode.Write);
                  cs.Write(inputByteArray,
      0, inputByteArray.Length);
                  cs.FlushFinalBlock();
                 
      return Encoding.Default.GetString(ms.ToArray());
              }

             
      #endregion
          }

      D.E.S 是分塊加密的,將明文分割成 64 BITS 的塊, 然后他們一個個接起來 。他使用56位密鑰對64位的數(shù)據(jù)塊進(jìn)行加密,并對64bits的數(shù)據(jù)塊進(jìn)行16輪編碼。和每輪編碼時,一個48bits的“每輪”密鑰值由56bits的完整密鑰得出來。DES用軟件進(jìn)行解碼需要用非常長時間,而用硬件解碼速度非?,1977年,人們估計要耗資兩千萬美元才能建成一個專門計算機(jī)用于DES的解密,而且需要12個小時的破解才能得到結(jié)果。所以,當(dāng)時DES被認(rèn)為是一種十分強(qiáng)壯的加密方法。但今天, 只需 二十萬美圓就能制造一臺破譯DES的特別的計算機(jī),所以目前 DES 對需求“強(qiáng)壯”加密的場合已不再適用了。

        相關(guān)評論

        閱讀本文后您有什么感想? 已有人給出評價!

        • 8 喜歡喜歡
        • 3 頂
        • 1 難過難過
        • 5 囧
        • 3 圍觀圍觀
        • 2 無聊無聊

        熱門評論

        最新評論

        發(fā)表評論 查看所有評論(0)

        昵稱:
        表情: 高興 可 汗 我不要 害羞 好 下下下 送花 屎 親親
        字?jǐn)?shù): 0/500 (您的評論需要經(jīng)過審核才能顯示)