title: Rijndael: Same input / different output on multiple machines
body: <p>Some software i wrote uses the Rijndael algorithm from .Net4.0 to encrypt and decrypt license information.</p>
  
  <p>The Problem is as followed:
  The program generates a string, which is transformed into a byte[]. This byte[] is then encrypted with Rijndael into another byte[] which is then transferred to other computers.
  There, this encrypted byte[] is decrypted again and the resulting byte[] is transformed back again into a string to retrieve the information from it.</p>
  
  <p>Basically this works perfectly fine ... but not that perfect i guess.</p>
  
  <p>There is one computer in our office that seems to encrypt and decrypt in a different way.</p>
  
  <p>If i try to decrypt the byte[] on another computer, it gives me something like that:</p>
  
  <pre><code>{"Zeichenabstände sind ungültig und können nicht entfernt werden."}
   bei System.Security.Cryptography.RijndaelManagedTransform.DecryptData(Byte[] inputBuffer, Int32 inputOffset, Int32 inputCount, Byte[]&amp; outputBuffer, Int32 outputOffset, PaddingMode paddingMode, Boolean fLast)
   bei System.Security.Cryptography.RijndaelManagedTransform.TransformFinalBlock(Byte[] inputBuffer, Int32 inputOffset, Int32 inputCount)
   bei System.Security.Cryptography.CryptoStream.FlushFinalBlock()
   bei System.Security.Cryptography.CryptoStream.Dispose(Boolean disposing)
   bei System.IO.Stream.Close()
  </code></pre>
  
  <p>The code doing the encryption looks like this:</p>
  
  <pre><code>private byte[] EncryptBytes(byte[] originalBytes) {
      MemoryStream ms = new MemoryStream();
      Rijndael crypt = Rijndael.Create();
      crypt.Key = KeyBytes;
      crypt.IV = IVBytes;
      CryptoStream cs = new CryptoStream(ms, crypt.CreateEncryptor(), CryptoStreamMode.Write);
      cs.Write(originalBytes, 0, originalBytes.Length);
      cs.Close();
      Byte[] cryptedBytes = ms.ToArray();
      ms.Close();
      return cryptedBytes;
  }
  </code></pre>
  
  <p>For decryption it's the same, just with CreateDecryptor() instead of CreateEncryptor().</p>
  
  <p>For testing and solving the problem, i did the following:</p>
  
  <p>On both computers i encrypted exactly the same string.
  I checked that this string is transformed into exactly the same byte[] on both machines.
  The Rijndael object has the same property values on both machines so its configured the same way (Key, IV, Padding etc.)</p>
  
  <p>The encrypted byte[] output afterwards is completely different on both machines.</p>
  
  <p>This is where I'm stuck. I can't think of a reason for this behaviour and neither could the internet help me. Both computers run Windows XP x86 with .Net4.0</p>
  
  <p>I am very gratefull for any hint and thank you in advance,
  mls</p>
  
  <p>Fun fact: It has worked fine on 12 different computers, machine 13 is bitching around :)</p>