title: Encrypting on NETMF, decrypting on .NET
body: <p>I was trying to use XTEA encryption on NETMF using the code from blog post <a href="http://www.dmcinfo.com/Blog/articleType/ArticleView/articleId/83/Encryption-Compatibility-Between-NET-Micro-Framework-and-the-Full-NET-Framework.aspx" rel="nofollow">Encryption Compatibility Between .NET Micro Framework and the Full .NET Framework</a>. The code used on the micro framework is the following.</p>
  
  <pre><code>public static string Encrypt(string message)
  {
      var key = "0x081632";
      var data = Encoding.UTF8.GetBytes(message);
      var xteaKey = Encoding.UTF8.GetBytes(key);
      var xtea = new Key_TinyEncryptionAlgorithm(xteaKey);
      var encryptedBytes = xtea.Encrypt(data, 0, data.Length, xteaKey);
      var encryptedString = ConvertBase64.ToBase64String(encryptedBytes);
      return encryptedString;
  }
  </code></pre>
  
  <p>The Base64 result is sent to an Azure web service. However, I am unable to decrypt this. I have tried several situations, but the .NET code is returning different results for the same key and message on .NET and NETMF.</p>
  
  <p>Is there a solution for this situation, or any other encryption scheme I can use? I prefer not to use RSA, as it can be a real performance hit on NETMF.</p>
  
  <p>Decryption code.</p>
  
  <pre><code>var k = Encoding.UTF8.GetBytes("0x081632");
  message = message.Replace("!", "+").Replace("*", "/"); // base64 on .netmf is different
  var m = Convert.FromBase64String(message);
  var xteaNet = new Key_TinyEncryptionAlgorithm(k); // class from blog
  var decBytes = xteaNet.Decrypt(m, 0, m.Length, k);
  var decString = Encoding.UTF8.GetString(decBytes);
  </code></pre>
  
  <p>It may be a little/big endian difference, but I'm not sure what parts of the code would have to be changed to allow for this.</p>
  
  <p>For testing, I tried to encode with data 8 long, and key 8 long, and now the result on both systems are equal. Data is "01234567", key is "0x081632", result after base64 "2BwR4Xe2sIk=".</p>