Home Forums Support Encryption and compression at one time

  • This topic has 3 replies, 3 voices, and was last updated 11 years ago by Anonymous.
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #1164
    Anonymous
    Inactive

    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.

    #1171
    Anonymous
    Inactive

    Compression 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,
    Marc

    #1172
    Anonymous
    Inactive

    Thank you for your your response. Now I see. It is really good library.

    #1188
    Anonymous
    Inactive

    I’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

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.