乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      asp.net URL參數(shù)加密解密的問(wèn)題

       mybook564 2014-09-15


        最近我遇到一個(gè)關(guān)于asp.net
      URL參數(shù)加密解密的問(wèn)題,在加密時(shí)沒(méi)問(wèn)題,可是解密就有問(wèn)題了,有些參數(shù)解密出來(lái)是空(并不是原來(lái)的數(shù)據(jù))。下面是一個(gè)需要加密URL參數(shù)的地
      址:http://www.px?username=marry&password=marry

        在index.aspx頁(yè)添加的代碼:

              private static byte[] key = { };

              private static byte[] IV = { 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF };

              private static string EncryptionKey = "!5623a#de"; 

              public static string Encrypt(string Input)

              {

                  try

                  {

                      key = System.Text.Encoding.UTF8.GetBytes(EncryptionKey.Substring(0, 8));

                      DESCryptoServiceProvider des = new DESCryptoServiceProvider();

                      Byte[] inputByteArray = Encoding.UTF8.GetBytes(Input);

                      MemoryStream ms = new MemoryStream();

                      CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(key, IV), CryptoStreamMode.Write);

                      cs.Write(inputByteArray, 0, inputByteArray.Length);

                      cs.FlushFinalBlock();

                      return Convert.ToBase64String(ms.ToArray());

                  }

                  catch (Exception ex)

                  {

                      return "";

                  }

              }

              Response.Redirect(“http://www.px?username=” + Encrypt(marry) + "&password=" Encrypt(marry

      ));



        在px網(wǎng)頁(yè)需要的代碼:

              private static byte[] key = { };

              private static byte[] IV = { 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF };

              private static string EncryptionKey = "!5623a#de";


             public static string Decrypt(string Input)

              {

                  if (!string.IsNullOrEmpty(Input))

                  {

                      Input = Input.Replace(" ", "+");


                      Byte[] inputByteArray = new Byte[Input.Length];

                      try

                      {

                          key = System.Text.Encoding.UTF8.GetBytes(EncryptionKey.Substring(0, 8));

                          DESCryptoServiceProvider des = new DESCryptoServiceProvider();

                          inputByteArray = Convert.FromBase64String(Input);

                          MemoryStream ms = new MemoryStream();

                          CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(key, IV), CryptoStreamMode.Write);

                          cs.Write(inputByteArray, 0, inputByteArray.Length);

                          cs.FlushFinalBlock();


                          Encoding encoding = Encoding.UTF8;

                          return encoding.GetString(ms.ToArray());


                      }

                      catch (Exception ex)

                      {

                          return "";

                      }

                  }

                  else

                  {

                      return "";

                  }

              }

      在Page_Load事件中要添加的代碼:

                  Decrypt(Request.QueryString["username"]);

                  Decrypt(Request.QueryString["password"]);



      總結(jié):如果去除紅色部分的代碼就會(huì)出現(xiàn)上面出現(xiàn)所說(shuō)的情況,出錯(cuò)或者解密出來(lái)的數(shù)據(jù)變成空值。


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

        0條評(píng)論

        發(fā)表

        請(qǐng)遵守用戶(hù) 評(píng)論公約

        類(lèi)似文章 更多