欢迎来到 IT实训基地-南通科迅教育
咨询电话:0513-81107100
C#中的Base64.DecodeBase64以及Inflater解码
2017/1/18
科迅教育
339
南通Web前端培训学校报名值得吗?

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中。

77
关闭
先学习,后交费申请表
每期5位名额
在线咨询
免费电话
QQ联系
先学习,后交费
TOP
您好,您想咨询哪门课程呢?
关于我们
机构简介
官方资讯
地理位置
联系我们
0513-91107100
周一至周六     8:30-21:00
微信扫我送教程
手机端访问
南通科迅教育信息咨询有限公司     苏ICP备15009282号     联系地址:江苏省南通市人民中路23-6号新亚大厦三楼             法律顾问:江苏瑞慈律师事务所     Copyright 2008-