Encryption Problems

Home Page › Forums › BizTalk 2004 – BizTalk 2010 › Encryption Problems

Viewing 0 reply threads
  • Author
    Posts
    • #16557

      I am testing the encryption/decryption of messages using a pipeline component, that I got from internet, in biztalk. It has two receive locations, one for file and the other is MSMQ. When I put the message in there using a file, it works alright and decrypts the message, but when I put the same message using a queue, it says bad data. By debugging the component I managed to find out that the data written from file has longer length and when I write the same using queue, it has less length and the last few characters are missing, like file data shows length of 336 and queue one shows 328.

      It is surprising because the stream that I use to write data to both file and msmq are same in length and data, Is that something the file adapter is doing to it, or perhaps the EOF characters at the end?, but again, that component is properly decrypting the files data which means that is in the correct format. Any idea why this might be happening?

      I am pasting the method I am using to generate and write streams of data to the file and queue:

      For File:

      ————-

      public static void EncryptFile(string sInputFilename,

      string sOutputFilename,

      KeyWrapper key)

      {

      FileStream fsInput = new FileStream(sInputFilename,

      FileMode.Open,

      FileAccess.Read);

      FileStream fsEncrypted = new FileStream(sOutputFilename,

      FileMode.Create,

      FileAccess.ReadWrite);

      DESCryptoServiceProvider DES = new DESCryptoServiceProvider();

       

      DES.Key = key.Key;

      DES.IV = key.IV;

      ICryptoTransform desencrypt = DES.CreateEncryptor();

      CryptoStream cryptostream = new CryptoStream(fsEncrypted,

      desencrypt,

      CryptoStreamMode.Write);

       

      byte[] bytearrayinput = new byte[fsInput.Length];

      fsInput.Read(bytearrayinput, 0, bytearrayinput.Length);

      string inPutString = Encoding.ASCII.GetString(bytearrayinput);

      cryptostream.Write(bytearrayinput, 0, bytearrayinput.Length);

      cryptostream.Close();

      fsInput.Close();

      fsEncrypted.Close();

      }

      For Queue:

      ——————

      static void EncryptFile(string sInputFilename,

      string sOutputFilename,

      KeyWrapper key)

      {

      FileStream fsInput = new FileStream(sInputFilename,

      FileMode.Open,

      FileAccess.Read);

      FileStream fsEncrypted = new FileStream(sOutputFilename,

      FileMode.Create,

      FileAccess.ReadWrite);

      DESCryptoServiceProvider DES = new DESCryptoServiceProvider();

       

      DES.Key = key.Key;

      DES.IV = key.IV;

      ICryptoTransform desencrypt = DES.CreateEncryptor();

      CryptoStream cryptostream = new CryptoStream(fsEncrypted,

      desencrypt,

      CryptoStreamMode.Write);

       

      byte[] bytearrayinput = new byte[fsInput.Length];

      fsInput.Read(bytearrayinput, 0, bytearrayinput.Length);

      string inPutString = Encoding.ASCII.GetString(bytearrayinput);

      cryptostream.Write(bytearrayinput, 0, bytearrayinput.Length);

      cryptostream.Close();

      fsInput.Close();

      fsEncrypted.Close();

      }

      For Queue:

      ——————

      string sOutputFilename,

      KeyWrapper key)

      {

      FileStream fsInput = new FileStream(sInputFilename,

      FileMode.Open,

      FileAccess.Read);

      FileStream fsEncrypted = new FileStream(sOutputFilename,

      FileMode.Create,

      FileAccess.ReadWrite);

      DESCryptoServiceProvider DES = new DESCryptoServiceProvider();

       

      DES.Key = key.Key;

      DES.IV = key.IV;

      ICryptoTransform desencrypt = DES.CreateEncryptor();

      CryptoStream cryptostream = new CryptoStream(fsEncrypted,

      desencrypt,

      CryptoStreamMode.Write);

       

      byte[] bytearrayinput = new byte[fsInput.Length];

      fsInput.Read(bytearrayinput, 0, bytearrayinput.Length);

      string inPutString = Encoding.ASCII.GetString(bytearrayinput);

      cryptostream.Write(bytearrayinput, 0, bytearrayinput.Length);

      cryptostream.Close();

      fsInput.Close();

      fsEncrypted.Close();

      }

      For Queue:

      ——————

      KeyWrapper key)

      {

      FileStream fsInput = new FileStream(sInputFilename,

      FileMode.Open,

      FileAccess.Read);

      FileStream fsEncrypted = new FileStream(sOutputFilename,

      FileMode.Create,

      FileAccess.ReadWrite);

      DESCryptoServiceProvider DES = new DESCryptoServiceProvider();

       

      DES.Key = key.Key;

      DES.IV = key.IV;

      ICryptoTransform desencrypt = DES.CreateEncryptor();

      CryptoStream cryptostream = new CryptoStream(fsEncrypted,

      desencrypt,

      CryptoStreamMode.Write);

       

      byte[] bytearrayinput = new byte[fsInput.Length];

      fsInput.Read(bytearrayinput, 0, bytearrayinput.Length);

      string inPutString = Encoding.ASCII.GetString(bytearrayinput);

      cryptostream.Write(bytearrayinput, 0, bytearrayinput.Length);

      cryptostream.Close();

      fsInput.Close();

      fsEncrypted.Close();

      }

      For Queue:

      ——————

      FileStream fsInput = new FileStream(sInputFilename,

      FileMode.Open,

      FileAccess.Read);

      FileStream fsEncrypted = new FileStream(sOutputFilename,

      FileMode.Create,

      FileAccess.ReadWrite);

      DESCryptoServiceProvider DES = new DESCryptoServiceProvider();

       

      DES.Key = key.Key;

      DES.IV = key.IV;

      ICryptoTransform desencrypt = DES.CreateEncryptor();

      CryptoStream cryptostream = new CryptoStream(fsEncrypted,

      desencrypt,

      CryptoStreamMode.Write);

       

      byte[] bytearrayinput = new byte[fsInput.Length];

      fsInput.Read(bytearrayinput, 0, bytearrayinput.Length);

      string inPutString = Encoding.ASCII.GetString(bytearrayinput);

      cryptostream.Write(bytearrayinput, 0, bytearrayinput.Length);

      cryptostream.Close();

      fsInput.Close();

      fsEncrypted.Close();

      }

      For Queue:

      ——————

      FileMode.Open,

      FileAccess.Read);

      FileStream fsEncrypted = new FileStream(sOutputFilename,

      FileMode.Create,

      FileAccess.ReadWrite);

      DESCryptoServiceProvider DES = new DESCryptoServiceProvider();

       

      DES.Key = key.Key;

      DES.IV = key.IV;

      ICryptoTransform desencrypt = DES.CreateEncryptor();

      CryptoStream cryptostream = new CryptoStream(fsEncrypted,

      desencrypt,

      CryptoStreamMode.Write);

       

      byte[] bytearrayinput = new byte[fsInput.Length];

      fsInput.Read(bytearrayinput, 0, bytearrayinput.Length);

      string inPutString = Encoding.ASCII.GetString(bytearrayinput);

      cryptostream.Write(bytearrayinput, 0, bytearrayinput.Length);

      cryptostream.Close();

      fsInput.Close();

      fsEncrypted.Close();

      }

      For Queue:

      ——————

      FileAccess.Read);

      FileStream fsEncrypted = new FileStream(sOutputFilename,

      FileMode.Create,

      FileAccess.ReadWrite);

      DESCryptoServiceProvider DES = new DESCryptoServiceProvider();

       

      DES.Key = key.Key;

      DES.IV = key.IV;

      ICryptoTransform desencrypt = DES.CreateEncryptor();

      CryptoStream cryptostream = new CryptoStream(fsEncrypted,

      desencrypt,

      CryptoStreamMode.Write);

       

      byte[] bytearrayinput = new byte[fsInput.Length];

      fsInput.Read(bytearrayinput, 0, bytearrayinput.Length);

      string inPutString = Encoding.ASCII.GetString(bytearrayinput);

      cryptostream.Write(bytearrayinput, 0, bytearrayinput.Length);

      cryptostream.Close();

      fsInput.Close();

      fsEncrypted.Close();

      }

      For Queue:

      ——————

      FileStream fsEncrypted = new FileStream(sOutputFilename,

      FileMode.Create,

      FileAccess.ReadWrite);

      DESCryptoServiceProvider DES = new DESCryptoServiceProvider();

       

      DES.Key = key.Key;

      DES.IV = key.IV;

      ICryptoTransform desencrypt = DES.CreateEncryptor();

      CryptoStream cryptostream = new CryptoStream(fsEncrypted,

      desencrypt,

      CryptoStreamMode.Write);

       

      byte[] bytearrayinput = new byte[fsInput.Length];

      fsInput.Read(bytearrayinput, 0, bytearrayinput.Length);

      string inPutString = Encoding.ASCII.GetString(bytearrayinput);

      cryptostream.Write(bytearrayinput, 0, bytearrayinput.Length);

      cryptostream.Close();

      fsInput.Close();

      fsEncrypted.Close();

      }

      For Queue:

      ——————

      FileMode.Create,

      FileAccess.ReadWrite);

      DESCryptoServiceProvider DES = new DESCryptoServiceProvider();

       

      DES.Key = key.Key;

      DES.IV = key.IV;

      ICryptoTransform desencrypt = DES.CreateEncryptor();

      CryptoStream cryptostream = new CryptoStream(fsEncrypted,

      desencrypt,

      CryptoStreamMode.Write);

       

      byte[] bytearrayinput = new byte[fsInput.Length];

      fsInput.Read(bytearrayinput, 0, bytearrayinput.Length);

      string inPutString = Encoding.ASCII.GetString(bytearrayinput);

      cryptostream.Write(bytearrayinput, 0, bytearrayinput.Length);

      cryptostream.Close();

      fsInput.Close();

      fsEncrypted.Close();

      }

      For Queue:

      ——————

      FileAccess.ReadWrite);

      DESCryptoServiceProvider DES = new DESCryptoServiceProvider();

       

      DES.Key = key.Key;

      DES.IV = key.IV;

      ICryptoTransform desencrypt = DES.CreateEncryptor();

      CryptoStream cryptostream = new CryptoStream(fsEncrypted,

      desencrypt,

      CryptoStreamMode.Write);

       

      byte[] bytearrayinput = new byte[fsInput.Length];

      fsInput.Read(bytearrayinput, 0, bytearrayinput.Length);

      string inPutString = Encoding.ASCII.GetString(bytearrayinput);

      cryptostream.Write(bytearrayinput, 0, bytearrayinput.Length);

      cryptostream.Close();

      fsInput.Close();

      fsEncrypted.Close();

      }

      For Queue:

      ——————

      DESCryptoServiceProvider DES = new DESCryptoServiceProvider();

       

      DES.Key = key.Key;

      DES.IV = key.IV;

      ICryptoTransform desencrypt = DES.CreateEncryptor();

      CryptoStream cryptostream = new CryptoStream(fsEncrypted,

      desencrypt,

      CryptoStreamMode.Write);

       

      byte[] bytearrayinput = new byte[fsInput.Length];

      fsInput.Read(bytearrayinput, 0, bytearrayinput.Length);

      string inPutString = Encoding.ASCII.GetString(bytearrayinput);

      cryptostream.Write(bytearrayinput, 0, bytearrayinput.Length);

      cryptostream.Close();

      fsInput.Close();

      fsEncrypted.Close();

      }

      For Queue:

      ——————

      ICryptoTransform desencrypt = DES.CreateEncryptor();

      CryptoStream cryptostream = new CryptoStream(fsEncrypted,

      desencrypt,

      CryptoStreamMode.Write);

       

      byte[] bytearrayinput = new byte[fsInput.Length];

      fsInput.Read(bytearrayinput, 0, bytearrayinput.Length);

      string inPutString = Encoding.ASCII.GetString(bytearrayinput);

      cryptostream.Write(bytearrayinput, 0, bytearrayinput.Length);

      cryptostream.Close();

      fsInput.Close();

      fsEncrypted.Close();

      }

      For Queue:

      ——————

      CryptoStream cryptostream = new CryptoStream(fsEncrypted,

      desencrypt,

      CryptoStreamMode.Write);

       

      byte[] bytearrayinput = new byte[fsInput.Length];

      fsInput.Read(bytearrayinput, 0, bytearrayinput.Length);

      string inPutString = Encoding.ASCII.GetString(bytearrayinput);

      cryptostream.Write(bytearrayinput, 0, bytearrayinput.Length);

      cryptostream.Close();

      fsInput.Close();

      fsEncrypted.Close();

      }

      For Queue:

      ——————

      CryptoStreamMode.Write);

       

      byte[] bytearrayinput = new byte[fsInput.Length];

      fsInput.Read(bytearrayinput, 0, bytearrayinput.Length);

      string inPutString = Encoding.ASCII.GetString(bytearrayinput);

      cryptostream.Write(bytearrayinput, 0, bytearrayinput.Length);

      cryptostream.Close();

      fsInput.Close();

      fsEncrypted.Close();

      }

      For Queue:

      ——————

      byte[] bytearrayinput = new byte[fsInput.Length];

      fsInput.Read(bytearrayinput, 0, bytearrayinput.Length);

      string inPutString = Encoding.ASCII.GetString(bytearrayinput);

      cryptostream.Write(bytearrayinput, 0, bytearrayinput.Length);

      cryptostream.Close();

      fsInput.Close();

      fsEncrypted.Close();

      }

      For Queue:

      ——————

      string inPutString = Encoding.ASCII.GetString(bytearrayinput);

      cryptostream.Write(bytearrayinput, 0, bytearrayinput.Length);

      cryptostream.Close();

      fsInput.Close();

      fsEncrypted.Close();

      }

      For Queue:

      ——————

      For Queue:

      ——————

      public static MemoryStream EncryptMessage(string sInMsg,

      KeyWrapper key)

      {

      FileStream fsInput = new FileStream(@"C:\BizIn\SimpleFailureRoutingTest \SimpleFailureMessageTestInSchema_output.xml",

      FileMode.Open,

      FileAccess.Read);

      static MemoryStream EncryptMessage(string sInMsg,

      KeyWrapper key)

      {

      FileStream fsInput = new FileStream(@"C:\BizIn\SimpleFailureRoutingTest \SimpleFailureMessageTestInSchema_output.xml",

      FileMode.Open,

      FileAccess.Read);

      KeyWrapper key)

      {

      FileStream fsInput = new FileStream(@"C:\BizIn\SimpleFailureRoutingTest \SimpleFailureMessageTestInSchema_output.xml",

      FileMode.Open,

      FileAccess.Read);

      FileStream fsInput = new FileStream(@"C:\BizIn\SimpleFailureRoutingTest \SimpleFailureMessageTestInSchema_output.xml",

      FileMode.Open,

      FileAccess.Read);

      FileMode.Open,

      FileAccess.Read);

      FileAccess.Read);

      MemoryStream outputStream = new MemoryStream();

      DESCryptoServiceProvider DES = new DESCryptoServiceProvider();

      MemoryStream outputStream = new MemoryStream();

      DESCryptoServiceProvider DES = new DESCryptoServiceProvider();

      DESCryptoServiceProvider DES = new DESCryptoServiceProvider();

      DES.Key = key.Key;

      DES.IV = key.IV;

      ICryptoTransform desencrypt = DES.CreateEncryptor();

      ICryptoTransform desencrypt = DES.CreateEncryptor();

      CryptoStream cryptostream = new CryptoStream(outputStream,

      desencrypt,

      CryptoStreamMode.Write);

      CryptoStream cryptostream = new CryptoStream(outputStream,

      desencrypt,

      CryptoStreamMode.Write);

      CryptoStreamMode.Write);

      byte[] bytearrayinput = new byte[fsInput.Length];

      fsInput.Read(bytearrayinput, 0, bytearrayinput.Length);

      cryptostream.Write(bytearrayinput, 0, bytearrayinput.Length);

      return outputStream;

      }

      The fsEncrypted FileStream in the first method and the outputStream MemoryStream in the second method have the same size (for same file to be encrypted offcourse), I've checked that but still when they get written to queue and file and biztalk picks the message up, there size differs and queue's message is 8 characters shorter than the file one.

      Please help!!

       

      Regards,

      Sajid.

      byte[] bytearrayinput = new byte[fsInput.Length];

      fsInput.Read(bytearrayinput, 0, bytearrayinput.Length);

      cryptostream.Write(bytearrayinput, 0, bytearrayinput.Length);

      return outputStream;

      }

      The fsEncrypted FileStream in the first method and the outputStream MemoryStream in the second method have the same size (for same file to be encrypted offcourse), I've checked that but still when they get written to queue and file and biztalk picks the message up, there size differs and queue's message is 8 characters shorter than the file one.

      Please help!!

       

      Regards,

      Sajid.

      return outputStream;

      }

      The fsEncrypted FileStream in the first method and the outputStream MemoryStream in the second method have the same size (for same file to be encrypted offcourse), I've checked that but still when they get written to queue and file and biztalk picks the message up, there size differs and queue's message is 8 characters shorter than the file one.

      Please help!!

       

      Regards,

      Sajid.

       

Viewing 0 reply threads
  • The forum ‘BizTalk 2004 – BizTalk 2010’ is closed to new topics and replies.