SkillAgentSearch skills...

Crypto

:books: Provides a handy way to hash data using Adler32, CRC (8-bit to 82-bit, and customizable without bit restriction), MD5, SHA-1, SHA-2 and SHA-3 (256-bit, 384-bit and 512-bit), including HMAC keyed hashing for some types. Functions for encrypting and decrypting data with Rijndael (128-bit, 192-bit and 256-bit) are also offered

Install / Use

/learn @Roydl/Crypto

README

<p align="center"> <a href="https://dotnet.microsoft.com/download/dotnet/10.0" rel="nofollow"><img src="https://img.shields.io/badge/Core%2010%20LTS-or%20higher-lightgrey?style=for-the-badge&logo=dotnet&logoColor=white" title=".NET10 LTS or higher" alt=".NET Core"></a> <a href="https://github.com/Roydl/Crypto/actions"><img src="https://img.shields.io/badge/cross%E2%80%93platform-%e2%9c%94-blue?style=for-the-badge&logo=linux&logoColor=silver" title="Automatically tested with Windows 11 &amp; Ubuntu 24.04 LTS" alt="Cross-platform"></a> <a href="https://github.com/Roydl/Crypto/blob/master/LICENSE.txt"><img src="https://img.shields.io/github/license/Roydl/Crypto?style=for-the-badge" title="Read the license terms" alt="License"></a> </p> <p align="center"> <a href="https://github.com/Roydl/Crypto/actions/workflows/dotnet.yml"><img src="https://img.shields.io/github/actions/workflow/status/Roydl/Crypto/dotnet.yml?label=build%2Btest&logo=github&logoColor=silver&style=for-the-badge" title="Check the last workflow results" alt="Build+Test"></a> <a href="https://github.com/Roydl/Crypto/commits/master"><img src="https://img.shields.io/github/last-commit/Roydl/Crypto?style=for-the-badge&logo=github&logoColor=silver" title="Check the last commits" alt="Commits"></a> <a href="https://github.com/Roydl/Crypto/releases"><img src="https://img.shields.io/github/v/release/Roydl/Crypto?style=for-the-badge&logo=github&logoColor=silver" title="Check the latest release" alt="Releases"></a> <a href="https://github.com/Roydl/Crypto/archive/refs/heads/master.zip"><img src="https://img.shields.io/badge/download-source-important?style=for-the-badge&logo=github&logoColor=silver" title="Start downloading the &apos;master.zip&apos; file" alt="Source"></a> </p> <p align="center"> <a href="https://www.nuget.org/packages/Roydl.Crypto"><img src="https://img.shields.io/nuget/v/Roydl.Crypto?style=for-the-badge&logo=nuget&logoColor=silver&label=nuget" title="Check out the NuGet package page" alt="NuGet"></a> <a href="https://www.nuget.org/packages/Roydl.Crypto"><img src="https://img.shields.io/nuget/dt/Roydl.Crypto?logo=nuget&logoColor=silver&style=for-the-badge" title="Check out the NuGet package page" alt="NuGet"></a> <a href="https://www.si13n7.com"><img src="https://img.shields.io/website/https/www.si13n7.com?style=for-the-badge&down_color=critical&down_message=down&up_color=success&up_message=up&logo=data%3Aimage%2Fpng%3Bbase64%2CiVBORw0KGgoAAAANSUhEUgAAAA4AAAAOCAYAAAAfSC3RAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAEwSURBVDhPxZJNSgNBEIXnCp5AcCO4CmaTRRaKBhdCFkGCCKLgz2Y2RiQgCiqZzmi3CG4COj0X8ApewSt4Ba%2FQ9leZGpyVG8GComtq3qv3qmeS%2Fw9nikHMd5sVn3bqLx7zom1NcW8z%2F6G9CjoPm722rPEv45EJ21vD0O30AvX12IWDvTRsrPXrnjPlUYO0u3McVpZXhch5cnguZ7vVDWfpjRAZgPqc%2BIMEgKQe9Pfr0xn%2FBqZJjAUNQKilp5cC1gHYYz8Usc3OQsTz9HZWK5BMJwFDwrbWbuIXhfhg%2FDpWuE2mK5lEgQtiz4baU14u3V09i5peiipy6qVAxFWtZiflJiq8AAiIZx1CnxpStGmEpEHDZf4r2pUd%2BMjYxomoxJofo4L%2FHqyR57OF6vEvIkm%2BAYRc%2BWd4P97CAAAAAElFTkSuQmCC" title="Visit the developer&apos;s website" alt="Website"></a> <a href="https://www.si13n7.de"><img src="https://img.shields.io/website/https/www.si13n7.de?style=for-the-badge&down_color=critical&down_message=down&label=mirror&up_color=success&up_message=up&logo=data%3Aimage%2Fpng%3Bbase64%2CiVBORw0KGgoAAAANSUhEUgAAAA4AAAAOCAYAAAAfSC3RAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAEwSURBVDhPxZJNSgNBEIXnCp5AcCO4CmaTRRaKBhdCFkGCCKLgz2Y2RiQgCiqZzmi3CG4COj0X8ApewSt4Ba%2FQ9leZGpyVG8GComtq3qv3qmeS%2Fw9nikHMd5sVn3bqLx7zom1NcW8z%2F6G9CjoPm722rPEv45EJ21vD0O30AvX12IWDvTRsrPXrnjPlUYO0u3McVpZXhch5cnguZ7vVDWfpjRAZgPqc%2BIMEgKQe9Pfr0xn%2FBqZJjAUNQKilp5cC1gHYYz8Usc3OQsTz9HZWK5BMJwFDwrbWbuIXhfhg%2FDpWuE2mK5lEgQtiz4baU14u3V09i5peiipy6qVAxFWtZiflJiq8AAiIZx1CnxpStGmEpEHDZf4r2pUd%2BMjYxomoxJofo4L%2FHqyR57OF6vEvIkm%2BAYRc%2BWd4P97CAAAAAElFTkSuQmCC" title="Visit the developer&apos;s mirror website" alt="Mirror"></a> </p>

Roydl.Crypto

Roydl.Crypto provides a simple, generic way to hash virtually any .NET type. Generic extensions are available for almost every type, and a growing set of algorithms is offered — some of which are performance-optimized and likely more powerful than any other pure C# library of their kind.

Table of Contents


Prerequisites

  • .NET 10 LTS or higher
  • Supported platforms: Windows, Linux, macOS
  • Hardware acceleration (optional): SSE4.2, SSSE3, AVX2, or AVX-512 capable CPU

Install

$ dotnet add package Roydl.Crypto

Checksum Algorithms

| Name | Bit Width | Algorithm | Type | Hardware Support | | :---- | ----: | :---- | :---- | :----: | | Adler-32 | 32-bit | Standard | Cyclic | AVX-512 <br> AVX2 <br> SSSE3 | | CRC | from 8-bit<br>to 82-bit | 88 presets available + customizable | Cyclic | iSCSI @ SSE4.2 CPU <br> iSCSI+PKZip @ ARM | | MD5 | 128-bit | Built-in + HMAC keyed-hash support | Cryptographic | See ¹ | | SHA1 | 160-bit | Built-in + HMAC keyed-hash support | Cryptographic | See ¹ | | SHA2 | 256-bit<br>384-bit<br>512-bit | Built-in + HMAC keyed-hash support | Cryptographic | See ¹ | | SHA3 | 256-bit<br>384-bit<br>512-bit | Built-in + HMAC keyed-hash support | Cryptographic | See ¹ |

¹ Hardware acceleration for cryptographic algorithms is handled transparently by the .NET runtime and depends on the underlying platform (e.g. Intel SHA Extensions for SHA1 and SHA2-256 on supported CPUs).


Checksum Performance

Especially for Adler and CRC, the performance in software mode should be much better than with any other pure C# library, but similar to libraries that work with C/C++ imports. However, I couldn't find any other library with hardware support, not even with imports.

| Algorithm | Library | Mode | Speed | | :---- | :----: | :----: | ----: | | Adler-32 | This | Software | 3028.4 MiB/s | | Adler-32 | This | Hardware (SSSE3) | 36449.9 MiB/s | | Adler-32 | This | Hardware (AVX2) | 73427.1 MiB/s | | CRC-32 | Crc32.NET | Software | 2334.3 MiB/s | | CRC-32 | This | Software | 3098.6 MiB/s | | CRC-32 | This | Hardware | 12910.5 MiB/s | | SHA2-256 | Built-in | Software | 2282.7 MiB/s | | SHA3-256 | Built-in | Software | 670.5 MiB/s |

<details> <summary>Benchmark methodology</summary>

| Component | Details | | :--- | :--- | | CPU | AMD Ryzen 5 7600 (6C/12T, 5.1 GHz boost) | | RAM | 32 GB DDR5 | | OS | Manjaro Linux (Kernel 6.19.2-1) | | Runtime | .NET 10 | | Build | Release (dotnet run -c Release) |

In the test case, a 64 KiB packet with random bytes is generated, which is sent over and over again within 9 seconds by the function that computes the hash. During this process, it is determined several times how much data could be hashed within 1 second. 9 seconds proved to be the optimal duration — increasing this time does not provide more accurate results. Running multiple repetitions yields more reliable results: all individual values are recorded, outliers identified via min/max comparison, and the final result taken as the average of 20 runs. You can find the test case here.

</details>

Usage

GetChecksum & GetCipher

The GetChecksum extension method retrieves a string representation of the computed hash.

_The value can be almost anything: bool, sbyte, byte, short, ushort, char, int, uint, long, ulong, Half, float

View on GitHub
GitHub Stars11
CategoryDevelopment
Updated5d ago
Forks1

Languages

C#

Security Score

95/100

Audited on Mar 18, 2026

No findings