Cryptography
TinyCLR provides both the standard .NET cryptography algorithms (RSA, AES, etc.) and a TinyCLR-specific lightweight XTEA symmetric cipher.
NuGet package: GHIElectronics.TinyCLR.Cryptography.
Standard .NET cryptography
The standard cryptographic primitives from System.Security.Cryptography behave the same as on desktop .NET — RSACryptoServiceProvider, AesCryptoServiceProvider, and friends. For algorithm details, parameter semantics, and full API documentation, see Microsoft's System.Security.Cryptography reference. For the exact subset of methods TinyCLR exposes, see the System.Security.Cryptography API reference.
For network security, TLS wraps these primitives in a high-level API — most applications won't touch raw RSA/AES directly.
XTEA
XTEA (eXtended Tiny Encryption Algorithm) is a lightweight symmetric block cipher — much smaller and faster than AES, useful when you need symmetric encryption on tight RAM/CPU budgets and don't need a current-standard cipher. It's part of TinyCLR's library and isn't in standard .NET.
Key facts about TinyCLR's XTEA implementation:
- Key: always 128 bits (four
uintvalues). Any other key size throws. - Data: must be a multiple of 8 bytes. Pad your input if needed.
- Rounds: TinyCLR always uses 32 rounds. If you're decrypting TinyCLR output on a PC (or vice versa), make sure the PC implementation uses 32 rounds too.
using GHIElectronics.TinyCLR.Cryptography;
using System.Diagnostics;
using System.Text;
// 128-bit key — four 32-bit values.
var crypto = new Xtea(new uint[] { 0x01234567, 0x89ABCDEF, 0xFEDCBA98, 0x76543210 });
var dataToEncrypt = Encoding.UTF8.GetBytes("Data to encrypt."); // 16 bytes — multiple of 8.
var encrypted = crypto.Encrypt(dataToEncrypt, 0, (uint)dataToEncrypt.Length);
var decrypted = crypto.Decrypt(encrypted, 0, (uint)encrypted.Length);
Debug.WriteLine("Decrypted: " + Encoding.UTF8.GetString(decrypted));
// Decrypted: Data to encrypt.
XTEA is not a current-standard cipher. For new designs that need symmetric encryption, prefer AES from System.Security.Cryptography — it's faster on most modern hardware, has wider library compatibility, and is the choice every audit will expect. Reach for XTEA only for compatibility with existing TinyCLR 2 code, or in extreme footprint-constrained scenarios.
API reference
| Namespace | Description |
|---|---|
| GHIElectronics.TinyCLR.System.Security.Cryptography | RSA, AES, ECC, SHA, HMAC, and certificate classes |