We no longer sell products directly from the GHI Electronics website, click here for more details. Please find a Distributor to complete your online order. If you have any questions regarding this notice please contact us at support@ghielectronics.com.

XTEA

Last modified August 6, 2014

Required

Tutorials:  First NETMF Project

Introduction

XTEA is a secure encryption algorithm, though not as secure as RSA or others, that uses a 128bit key and requires very little processing power.

Warning

Make sure you only attempt to encrypt arrays with a size divisible by eight.

Getting Started

The following example shows the basic encryption and decryption of a string. When you use the parameterless constructor of the Xtea object, a key is generated for you that you can find in the Key property. If you pass a key to the constructor, it will be used instead.

using GHI.Utilities;
using Microsoft.SPOT;
using System.Text;

public class Program
{
    public static void Main()
    {
        var xtea = new Xtea();

        var encrypted = xtea.Encrypt(Encoding.UTF8.GetBytes("0123456776543210"));
        var decrypted = xtea.Decrypt(encrypted);

        Debug.Print(new string(Encoding.UTF8.GetChars(decrypted))); //should be "0123456776543210"

        var keyStr = "0x";
        for (int i = 0; i < Xtea.KeyLength; i++)
            keyStr += xtea.Key[i].ToString("x2");

        Debug.Print("The key used was " + keyStr);
    }
}
Leave feedback about this document.
Let us know if the information presented here was accurate, helpful and if you have any suggestions.
Leave feedback about this document.
Let us know if the information presented here was accurate, helpful and if you have any suggestions.

* Indicates required fields.
This form is only for feedback not support.
Review our how to find information guide on locating helpful resources.