Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7413929
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:58:39+00:00 2026-05-29T06:58:39+00:00

I was trying to use XTEA encryption on NETMF using the code from blog

  • 0

I was trying to use XTEA encryption on NETMF using the code from blog post Encryption Compatibility Between .NET Micro Framework and the Full .NET Framework. The code used on the micro framework is the following.

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;
}

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.

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.

Decryption 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);

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.

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=”.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T06:58:40+00:00Added an answer on May 29, 2026 at 6:58 am

    I created a new .NET micro framework v4.1 console application using a copy/paste of the encrypt method.

    In the same solution I added a new .NET 4.0 test project, which referenced the sample Key_TinyEncryptionAlgorithm class from the blog. I used the returned value from the Encrypt method 2BwR4Xe2sIk= and this was used as the test data for the unit test which decrypted the string successfully back into 01234567.

    I would assume your transport mechanism is causing the problem. The message over the wire is being modified and so what arrives at your service is not equivalent to what left the device.

    Perhaps just a classic serialization problem…

    All x86 and machines are little-endian. The .NET Micro Framework emulator reports via SystemInfo.IsBigEndian that the emulated environment is little-endian as well.

    It is common to tranmit data over a network in big-endian order though. If you want to reverse the bytes on the recieving end the following method should flip the order for you. I put this into the Key_TinyEncryptionAlgorithm class.

    private static byte[] ReverseBytes(byte[] inArray)
    {
      byte temp;
      int highCtr = inArray.Length - 1;
    
      for (int ctr = 0; ctr < inArray.Length / 2; ctr++)
      {
          temp = inArray[ctr];
          inArray[ctr] = inArray[highCtr];
          inArray[highCtr] = temp;
          highCtr -= 1;
       }
       return inArray;
    }
    

    And usage in the decryption method.

    Console.WriteLine(BitConverter.ToString(m));
    m = Key_TinyEncryptionAlgorithm.ReverseBytes(m);
    Console.WriteLine(BitConverter.ToString(m));
    

    Produces this output

    D8-1C-11-E1-77-B6-B0-89

    89-B0-B6-77-E1-11-1C-D8

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying use MySql and Entity Framework, using Connector/Net 6.1 with this as
I'm trying use mod_rewrite to rewrite URLs from the following: http://www.site.com/one-two-file.php to http://www.site.com/one/two/file.php The
Trying to use this code to connect the AD PrincipalContext context = new PrincipalContext(ContextType.Domain,
I'm trying to use ARCFOUR algorithm in my PHP code: $td = mcrypt_module_open(MCRYPT_ARCFOUR, '',
Anyone know how to create a cvCreateStructuringElementEx using a image? I'm trying use opencv.cv.cvCreateStructuringElementEx()
I am trying use std::copy to copy from two different iterator. But during course
I'm trying use make a div's background transparent using a mixture of CSS3 rgba()
i'm trying use webview to load a image from sdcard i use this path
Trying to use RSS.NET . Example on the site is: (C#) string url =
I'm trying use to selenium with firefox on CentOS from command line like this:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.