Hashing
TinyCLR exposes both the standard .NET hash algorithms (MD5, SHA-1, HMAC variants) and a TinyCLR-specific CRC16 for error detection.
NuGet package: GHIElectronics.TinyCLR.Cryptography.
Standard .NET hashes
The following algorithms behave identically to their desktop .NET counterparts — use the same code you'd use on a PC. For algorithm details, parameter semantics, and the full API surface, see Microsoft's System.Security.Cryptography documentation. For the exact subset of methods TinyCLR exposes, see the System.Security.Cryptography API reference.
MD5— legacy 128-bit hash. Don't use for security; useful for cache keys, file fingerprinting.SHA1— 160-bit hash. Considered cryptographically weak; still useful for non-security integrity checks.HMACSHA1— keyed message authentication code built on SHA-1.HMACSHA256— keyed message authentication code built on SHA-256. Required for Shared Access Signatures when integrating with Azure.
CRC16
Crc16 is a 16-bit cyclic redundancy check — fast error detection for serial protocols, packet framing, and stored data. It's part of TinyCLR's library and isn't in standard .NET.
Hash an entire buffer in one call:
using GHIElectronics.TinyCLR.Cryptography;
var crc = new Crc16();
var data = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 };
var hash = crc.ComputeHash(data, 0, data.Length);
Or hash in chunks — pass the running hash back into the next call to continue from where the previous chunk left off:
var crc = new Crc16();
var data = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 };
// Hash the first 3 bytes.
var partial = crc.ComputeHash(data, 0, 3);
// Hash the next byte, continuing from the previous result.
var combined = crc.ComputeHash(data, 3, 1, partial);
This is useful when the data arrives a chunk at a time (streamed from disk, received over UART) and you don't want to buffer the full payload before computing the CRC.
API reference
| Namespace | Description |
|---|---|
| GHIElectronics.TinyCLR.System.Security.Cryptography | SHA, MD5, HMAC, AES, and RSA cryptographic classes |