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

使用ASP.Net加密Cookie[2]

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

    {   //定義DES的Provider
    DESCryptoServiceProvider desprovider =
    new DESCryptoServiceProvider();
    //轉換解密的字符串為二進制
    byte[] buffer = ConvertFromBaseString(valueString);
    //定義內存流
    MemoryStream memoryStream = new MemoryStream();
    //定義加密流
    CryptoStream cryptoStream = new CryptoStream(memoryStream
    desproviderCreateEncryptor(KeyIV)
    CryptoStreamModeRead);
    //定義讀IO流
    StreamReader readerStream = new StreamReader(cryptoStream);
    //返回解密後的字符串
    return(readerStreamReadToEnd());
    }
    return(null);
    }
    public static String EncryptTripleDES(String valueString)
    {
    if(valueString != )
    {   //定義TripleDES的Provider
    TripleDESCryptoServiceProvider triprovider =
    new TripleDESCryptoServiceProvider();
    //定義內存流
    MemoryStream memoryStream = new MemoryStream();
    //定義加密流
    CryptoStream cryptoStream = new CryptoStream(memoryStream
    triproviderCreateEncryptor(KeyIV)
    CryptoStreamModeWrite);
    //定義寫IO流
    StreamWriter writerStream = new StreamWriter(cryptoStream);
    //寫入加密後的字符流
    writerStreamWrite(valueString);
    writerStreamFlush();
    cryptoStreamFlushFinalBlock();
    memoryStreamFlush();
    //返回加密後的字符串
    return(ConvertToBaseString(memoryStreamGetBuffer()
    (int)memoryStreamLength));
    }
    return(null);
    }
    public static String DecryptTripleDES(String valueString)
    {
    if(valueString != )
    {   //定義TripleDES的Provider
    TripleDESCryptoServiceProvider triprovider =
    new TripleDESCryptoServiceProvider();
    //轉換解密的字符串為二進制
    byte[] buffer = ConvertFromBaseString(valueString);
    //定義內存流
    MemoryStream memoryStream = new MemoryStream();
    //定義加密流

[]  []  []  []  []  


From:http://tw.wingwit.com/Article/program/net/201311/15125.html
    推薦文章
    Copyright © 2005-2013 電腦知識網 Computer Knowledge   All rights reserved.