Cryptography custom sink

Hello!
For my thesis i would like to contruct a custom sink wich encryptes my data.
I tried with tcp, binary formatter and Rijndael as crypto algorithm.. but it doesn’t work.
Here ist my encrypting code:

public Stream Encrypt(Stream source)
{
   try {
          RijndaelManaged myRijndael = new RijndaelManaged();
          byte[] toEncrypt = new byte[(int)source.Length];
          ICryptoTransform encryptor=myRijndael.CreateEncryptor(key,IV);                        
          CryptoStream csEncrypt = new CryptoStream(source, encryptor,CryptoStreamMode.Write);
          source.Read(toEncrypt,0,(int)source.Length);
          csEncrypt.Write(toEncrypt, 0, toEncrypt.Length);
          csEncrypt.FlushFinalBlock();
          source.Position = 0;
        }
     catch(Exception e)
    { System.Console.WriteLine("[EncryptionHelper.Encrypt()] "+e.Message); }
   return source;
}

 


And here decryption:

public Stream Decrypt(Stream source)
{
   try {
       int length = 0;
       byte [] fromEncrypt;
       while(source.ReadByte() != -1) { length++; }
       RijndaelManaged myRijndael = new RijndaelManaged();
       ICryptoTransform decryptor = myRijndael.CreateDecryptor(key, IV);
      CryptoStream csDecrypt = new CryptoStream(source, decryptor,CryptoStreamMode.Read);
       fromEncrypt = new byte[length];
       csDecrypt.Read(fromEncrypt, 0, length);
     }
   catch(Exception e)
  { System.Console.WriteLine("[EncryptionHelper.Decrypt()] "+e.Message); }
 return source;
}

 

I use the same key to encrypt and decrypt, but i always get an RemotingException with no reasons....Sad

Somebody an idea
Thanks


Answer this question

Cryptography custom sink

  • SchildB

    Yes, without the Sink it does work without problems.
    Here ist the Stack Trace:
    Server stack trace:
       at System.Runtime.Serialization.Formatters.Binary.__BinaryParser.Run()
       at System.Runtime.Serialization.Formatters.Binary.ObjectReader.Deserialize(HeaderHandler handler, __BinaryParser serParser, Boolean fCheck, IMethodCallMessage methodCallMessage)
       at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream, HeaderHandler handler, Boolean fCheck, IMethodCallMessage methodCallMessage)
       at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.UnsafeDeserializeMethodResponse(Stream serializationStream, HeaderHandler handler, IMethodCallMessage methodCallMessage)
       at System.Runtime.Remoting.Channels.CoreChannel.DeserializeBinaryResponseMessage(Stream inputStream, IMethodCallMessage reqMsg, Boolean bStrictBinding)
       at System.Runtime.Remoting.Channels.BinaryClientFormatterSink.DeserializeMessage(IMethodCallMessage mcm, ITransportHeaders headers, Stream stream)
       at System.Runtime.Remoting.Channels.BinaryClientFormatterSink.SyncProcessMessage(IMessage msg)

    Exception rethrown at [0]:
       at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
       at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
       at Remoting.IMitglied.speichereMitgliedsdaten(DataTable Daten)
       at Client.TransformatorSubjekt.speichern(DataTable data) in e:\iris\eigene programme\remotingsecurity\remotingsecurity\client\transformatorsubjekt.cs:line 61

    Thanks!

  • PeeJayGee

    I could help you figure this out, but since Whidbey supports this already, you should just make the channel secure.
  • rosch

    Hi Dya, does your code work correctly without the custom sink in place, or with a dummy sink that just prints out the message and then continues processing

    Also, can you attach the full stack trace that you're seeing

    Regards,
    JJustice [MSFT]

  • Bill R.

    Ok, and... how do i do that
    Could you give me a start
    Thanks!!

  • Cryptography custom sink