程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> C# >> C#入門知識 >> C#中的Base64.DecodeBase64以及Inflater解碼

C#中的Base64.DecodeBase64以及Inflater解碼

編輯:C#入門知識

print?public void Base64Test() 
       { 
           string baseStr = "eJyVjMENgDAMA1fpBMjnIkp3ZzZEpAa1PLmXY10sDdqBqr54Ww5AthG7zxJYa0MYr9p7bPFnK/uqjCj06y7JfHwAX3AhhA=="; 
           // Base64解碼  
           byte[] baseBytes = Convert.FromBase64String(baseStr); 
           // Inflater解壓  
           string resultStr = Decompress(baseBytes); 
 
 
           Console.WriteLine(resultStr); 
       } 
 
 
       /// <summary>  
       /// Inflater解壓  
       /// </summary>  
       /// <param name="baseBytes"></param>  
       /// <returns></returns>  
       public string Decompress(byte[] baseBytes) 
       { 
           string resultStr = string.Empty; 
           using (MemoryStream memoryStream = new MemoryStream(baseBytes)) 
           { 
               using (InflaterInputStream inf = new InflaterInputStream(memoryStream)) 
               { 
                   using (MemoryStream buffer = new MemoryStream()) 
                   { 
                       byte[] result = new byte[1024]; 
 
 
                       int resLen; 
                       while ((resLen = inf.Read(result, 0, result.Length)) > 0) 
                       { 
                           buffer.Write(result, 0, resLen); 
                       } 
                       resultStr = Encoding.Default.GetString(result); 
                   } 
               } 
           } 
           return resultStr; 
       } 

 public void Base64Test()
        {
            string baseStr = "eJyVjMENgDAMA1fpBMjnIkp3ZzZEpAa1PLmXY10sDdqBqr54Ww5AthG7zxJYa0MYr9p7bPFnK/uqjCj06y7JfHwAX3AhhA==";
            // Base64解碼
            byte[] baseBytes = Convert.FromBase64String(baseStr);
            // Inflater解壓
            string resultStr = Decompress(baseBytes);


            Console.WriteLine(resultStr);
        }


        /// <summary>
        /// Inflater解壓
        /// </summary>
        /// <param name="baseBytes"></param>
        /// <returns></returns>
        public string Decompress(byte[] baseBytes)
        {
            string resultStr = string.Empty;
            using (MemoryStream memoryStream = new MemoryStream(baseBytes))
            {
                using (InflaterInputStream inf = new InflaterInputStream(memoryStream))
                {
                    using (MemoryStream buffer = new MemoryStream())
                    {
                        byte[] result = new byte[1024];


                        int resLen;
                        while ((resLen = inf.Read(result, 0, result.Length)) > 0)
                        {
                            buffer.Write(result, 0, resLen);
                        }
                        resultStr = Encoding.Default.GetString(result);
                    }
                }
            }
            return resultStr;
        }

 

 

其中InflaterInputStream的類來自於ICSharpCode.SharpZipLib.dll中。


 

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved