Tagged: decompression, encryption
- This topic has 3 replies, 3 voices, and was last updated 11 years, 1 month ago by Anonymous.
-
AuthorPosts
-
November 14, 2013 at 10:13 #1164AnonymousInactive
Hello. I have a problem using encryption and compression together:
Following code I made in both server and client:
//ENCRYPTION: NetworkComms.DefaultSendReceiveOptions.DataProcessors.Add(DPSManager.GetDataProcessor<RijndaelPSKEncrypter>()); RijndaelPSKEncrypter.AddPasswordToOptions(NetworkComms.DefaultSendReceiveOptions.Options, "123123123"); //COMPRESSION NetworkComms.DefaultSendReceiveOptions.DataProcessors.Add(DPSManager.GetDataProcessor<SharpZipLibGzipCompressor>());
and I have following error (incorrect data length for decompression):
Base Exception Type: System.Security.Cryptography.CryptographicException: Недопустимая длина данных для дешифрования. в System.Security.Cryptography.RijndaelManagedTransform.TransformFinalBlock(Byte[] inputBuffer, Int32 inputOffset, Int32 inputCount) в System.Security.Cryptography.CryptoStream.FlushFinalBlock() в System.Security.Cryptography.CryptoStream.Dispose(Boolean disposing) в System.IO.Stream.Close() в System.IO.Stream.Dispose() в DPSBase.RijndaelPSKEncrypter.ReverseProcessDataStream(Stream inStream, Stream outStream, Dictionary&2 options, Int64& writtenBytes) в DPSBase.DataSerializer.DeserialiseGeneralObject[T](MemoryStream receivedObjectStream, List&1 dataProcessors, Dictionary&2 options) в DPSBase.DataSerializer.DeserialiseDataObject[T](MemoryStream receivedObjectStream, List&1 dataProcessors, Dictionary&2 options) в NetworkCommsDotNet.PacketTypeHandlerDelegateWrapper&1.DeSerialize(MemoryStream incomingBytes, SendReceiveOptions options) в NetworkCommsDotNet.NetworkComms.TriggerGlobalPacketHandlers(PacketHeader packetHeader, Connection connection, MemoryStream incomingDataStream, SendReceiveOptions options, Boolean ignoreUnknownPacketTypeOverride) Stack Trace: в System.Security.Cryptography.RijndaelManagedTransform.TransformFinalBlock(Byte[] inputBuffer, Int32 inputOffset, Int32 inputCount) в System.Security.Cryptography.CryptoStream.FlushFinalBlock() в System.Security.Cryptography.CryptoStream.Dispose(Boolean disposing) в System.IO.Stream.Close() в System.IO.Stream.Dispose() в DPSBase.RijndaelPSKEncrypter.ReverseProcessDataStream(Stream inStream, Stream outStream, Dictionary&2 options, Int64& writtenBytes) в DPSBase.DataSerializer.DeserialiseGeneralObject[T](MemoryStream receivedObjectStream, List&1 dataProcessors, Dictionary&2 options) в DPSBase.DataSerializer.DeserialiseDataObject[T](MemoryStream receivedObjectStream, List&1 dataProcessors, Dictionary&2 options) в NetworkCommsDotNet.PacketTypeHandlerDelegateWrapper&1.DeSerialize(MemoryStream incomingBytes, SendReceiveOptions options) в NetworkCommsDotNet.NetworkComms.TriggerGlobalPacketHandlers(PacketHeader packetHeader, Connection connection, MemoryStream incomingDataStream, SendReceiveOptions options, Boolean ignoreUnknownPacketTypeOverride)
When I comment out encyption, my program works well. When I comment out compression, my program works well. Not both.
November 14, 2013 at 10:39 #1171AnonymousInactiveCompression is already present by default so adding the encryption dataprocessor is sufficient. To confirm inspect the return value of
NetworkComms.DefaultSendReceiveOptions.DataProcessors
.Having said that it does look like a bug that adding a second compression step fails. I will create a bug report and we will fix this in the near future.
Regards,
MarcNovember 15, 2013 at 04:03 #1172AnonymousInactiveThank you for your your response. Now I see. It is really good library.
November 18, 2013 at 10:40 #1188AnonymousInactiveI’ve pushed a fix for this bug so hopefully it will not cause anybody else any further confusion. Thank you again for bringing it to our attention.
As an aside it is worth noting that data processors are applied in the order you add them and do not commute (i.e. the order matters). In other words in the above case you would be trying to compress encrypted data. As the encryption should be pretty good (AES) the data you’re trying to compress will look basically random and the compression step will not shrink the data size (it will actually probably increase it).
In other words always make sure you compress before you encrypt.
Regards
Matt
-
AuthorPosts
- You must be logged in to reply to this topic.