CSharp-AES-CTR-NetStandard
Managed .Net 8 compatible AES-CTR cipher written in C# (using AesManaged for AES operations)
GitHub
Documentation
How do I use this?
Either copy the CSAES-CTR.cs to your project or use LibAES-CTR nuget package
Then do code like
using CS_AES_CTR;
byte[] mySimpleTextAsBytes = Encoding.ASCII.GetBytes("Plain text I want to encrypt");
// In real world, generate these with cryptographically secure pseudo-random number generator (CSPRNG)
byte[] key = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 };
byte[] initialCounter = new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05 };
// Encrypt
AES_CTR forEncrypting = new AES_CTR(key, initialCounter);
byte[] encryptedContent = new byte[mySimpleTextAsBytes.Length];
forEncrypting.EncryptBytes(encryptedContent, mySimpleTextAsBytes);
// Decrypt
AES_CTR forDecrypting = new AES_CTR(key, initialCounter);
byte[] decryptedContent = new byte[encryptedContent.Length];
forDecrypting.DecryptBytes(decryptedContent, encryptedContent);
You can try out the code in .NET Fiddle
License
All the code in src and tests folders are licensed under Unlicense. SO sample code file (which is only used during benchmarking) is licensed under cc-wiki (aka cc-by-sa) license, see https://stackoverflow.blog/2009/06/25/attribution-required/