熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

使用ASP.Net加密Cookie[4]

2022-06-13   來源: .NET編程 
    ——此文章摘自《ASPNET網絡數據庫開發實例精解》定價 特價 詳細>>

    public static void SetEncryptedCookie(String keyString valueString)
    {   //設置使用DES加密後的Cookie
    key = EncryptStringEncrypt(key);
    valueString = EncryptStringEncrypt(valueString);
    SetCookie(keyvalueString);
    }
    public static void SetEncryptedCookie(String key
    String valueStringDateTime expires)
    {   //設置使用DES加密後的Cookie並設置Cookie的有效時間
    key = EncryptStringEncrypt(key);
    valueString = EncryptStringEncrypt(valueString);
    SetCookie(keyvalueStringexpires);
    }
    public static String GetTripleDESEncryptedCookieValue(String key)
    {   //獲取使用TripleDES解密後的Cookie
    key = EncryptStringEncryptTripleDES(key);
    String valueString = GetCookieValue(key);
    valueString = EncryptStringDecryptTripleDES(valueString);
    return(valueString);
    }
    public static String GetEncryptedCookieValue(String key)
    {   //獲取使用DES解密後的Cookie
    key = EncryptStringEncrypt(key);
    String valueString = GetCookieValue(key);
    valueString = EncryptStringDecrypt(valueString);
    return(valueString);
    }
    public static HttpCookie GetCookie(String key)
    {   //通過關鍵字獲取Cookie
    key = HttpContextCurrentServerUrlEncode(key);
    return(HttpContextCurrentRequestCookiesGet(key));
    }
    public static String GetCookieValue(String key)
    {   //通過關鍵字獲取Cookie的value
    String valueString = GetCookie(key)Value;
    valueString = HttpContextCurrentServerUrlDecode(valueString);
    return(valueString);
    }
    }

    .設計頁面EncryptCookiesaspx

    把應用程序Example__的默認頁面WebFormaspx重命名為 EncryptCookiesaspx並在頁面上添加個Label控件它們的名稱分別為TripleDESCookie EncryptCookie和myCookie分別用來顯示使用TripleDES加密後的Cookie的值使用DES加密後的Cookie的值和 Cookie的原始值頁面EncryptCookiesaspx的設計界面如圖所示
    頁面EncryptCookiesaspx的HTML設計代碼如下
    <asp:Label ID=myCookie Runat=server></asp:Label>
    <asp:Label ID=EncryptCookie Runat=server></asp:Label>
    <asp:Label ID=TripleDESCookie Runat=server></asp:Label>

[]  []  []  []  []  


From:http://tw.wingwit.com/Article/program/net/201311/15123.html
  • 上一篇文章:

  • 下一篇文章:
  • 推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.