积极答复者
GZipStream 提示不被支持

问题
答案
-
byte[] gzipbytes = DES.Decrypt(bytes, key, "");
System.IO.Compression.GZipStream gzip = new System.IO.Compression.GZipStream(new MemoryStream(gzipbytes), System.IO.Compression.CompressionMode.Decompress, true);
StreamReader reader = new StreamReader(gzip);
result = reader.ReadToEnd();
reader.Close();byte[] gzipbytes = DES.Decrypt(bytes, key, "");
背景:因为服务端返回的数据是先压缩后加密的,所以我需要解密后解压,用此方法解不出来
你好,
>>用这个组件转不出来,返回的内容是空的
对于解密后的byte[], 可以使用GZipStream.Read() 方法解压缩,详见以下示例代码:
byte[] gzipbytes = DES.Decrypt(bytes, key, ""); //Prepare for decompress System.IO.MemoryStream ms = new System.IO.MemoryStream(gzipbytes); System.IO.Compression.GZipStream sr = new System.IO.Compression.GZipStream(ms, System.IO.Compression.CompressionMode.Decompress); //Reset variable to collect uncompressed result gzipbytes = new byte[gzipbytes.Length]; //Decompress int rByte = sr.Read(gzipbytes, 0, gzipbytes.Length); //Transform byte[] unzip data to string System.Text.StringBuilder sB = new System.Text.StringBuilder(rByte); //Read the number of bytes GZipStream red and do not a for each bytes in //resultByteArray; for (int i = 0; i < rByte; i++) { sB.Append((char)byteArray[i]); } sr.Close(); ms.Close(); sr.Dispose(); ms.Dispose(); txtData.Text = sB.ToString();
经过测试,可以正常解压显示出密文。
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.- 已标记为答案 qwsf01115 2014年11月12日 8:06
2014年11月12日 6:48
全部回复
-
你好,
>>此页上注明了支持winphone8.0
因为这篇KB是机器翻译的,经过我测试,确实是在WP8中不支持,可见英文文档:
#GZipStream Class
http://msdn.microsoft.com/en-us/library/system.io.compression.gzipstream(v=vs.110).aspx.NET for Windows Phone apps
Supported in: Windows Phone 8.1>>但是在实际的环境中,并不能解压服务端传来的数据,请问谁能提供解决方案。
在WP8中,我们可以使用 Microsoft 官方推出的 NuGet package:
#Microsoft Compression
https://www.nuget.org/packages/Microsoft.Bcl.Compression/它是支持WP8和WP8.1的,以下是我在WP SL 8.0 项目中的测试代码:
private void Button_Click(object sender, RoutedEventArgs e) { //Read the Data From zip string ReadData = ""; GZipStream instream = new GZipStream(File.OpenRead("Assets/test.gz"), CompressionMode.Decompress); StreamReader reader = new StreamReader(instream); ReadData = reader.ReadToEnd(); reader.Close(); txtData.Text = ReadData; }
上面的代码是解压test.gz中的文本文件,读取出来显示到界面上:
这里还有一篇英文的文章关于如何使用这个API: http://blogs.msdn.com/b/dotnet/archive/2013/06/06/portable-compression-and-httpclient-working-together.aspxWe are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.2014年11月12日 3:38 -
byte[] gzipbytes = DES.Decrypt(bytes, key, "");
System.IO.Compression.GZipStream gzip = new System.IO.Compression.GZipStream(new MemoryStream(gzipbytes), System.IO.Compression.CompressionMode.Decompress, true);
StreamReader reader = new StreamReader(gzip);
result = reader.ReadToEnd();
reader.Close();byte[] gzipbytes = DES.Decrypt(bytes, key, "");
背景:因为服务端返回的数据是先压缩后加密的,所以我需要解密后解压,用此方法解不出来
2014年11月12日 6:21 -
byte[] gzipbytes = DES.Decrypt(bytes, key, "");
System.IO.Compression.GZipStream gzip = new System.IO.Compression.GZipStream(new MemoryStream(gzipbytes), System.IO.Compression.CompressionMode.Decompress, true);
StreamReader reader = new StreamReader(gzip);
result = reader.ReadToEnd();
reader.Close();byte[] gzipbytes = DES.Decrypt(bytes, key, "");
背景:因为服务端返回的数据是先压缩后加密的,所以我需要解密后解压,用此方法解不出来
你好,
>>用这个组件转不出来,返回的内容是空的
对于解密后的byte[], 可以使用GZipStream.Read() 方法解压缩,详见以下示例代码:
byte[] gzipbytes = DES.Decrypt(bytes, key, ""); //Prepare for decompress System.IO.MemoryStream ms = new System.IO.MemoryStream(gzipbytes); System.IO.Compression.GZipStream sr = new System.IO.Compression.GZipStream(ms, System.IO.Compression.CompressionMode.Decompress); //Reset variable to collect uncompressed result gzipbytes = new byte[gzipbytes.Length]; //Decompress int rByte = sr.Read(gzipbytes, 0, gzipbytes.Length); //Transform byte[] unzip data to string System.Text.StringBuilder sB = new System.Text.StringBuilder(rByte); //Read the number of bytes GZipStream red and do not a for each bytes in //resultByteArray; for (int i = 0; i < rByte; i++) { sB.Append((char)byteArray[i]); } sr.Close(); ms.Close(); sr.Dispose(); ms.Dispose(); txtData.Text = sB.ToString();
经过测试,可以正常解压显示出密文。
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.- 已标记为答案 qwsf01115 2014年11月12日 8:06
2014年11月12日 6:48