Some extension methods to help with cryptography.
A very simple library providing some extension methods for cryptographic purposes. Most of these methods try to be fluent by returning the output.
A MemoryStream is created internally, don't forget to dispose later.
The IV is automatically written to / read from the 16 first bytes of the output:
var key = new byte[] {/* key bytes */};
using var cipheredStream = await inputStream.AesEncryptAsync(key);
using var decipheredStream = await cipheredStream.AesDecryptAsync(key);
The IV is automatically written to / read from the 16 first bytes of the output:
var key = new byte[] {/* key bytes */};
using var cipheredStream = new MemoryStream();
await inputStream.AesEncryptAsync(cipheredStream, key);
using var decipheredStream = new MemoryStream();
await cipheredStream.AesDecryptAsync(decipheredStream, key);
The IV can also be explicitly defined:
var key = new byte[] {/* key bytes */};
var iv = new byte[] {/* IV bytes */};
using var cipheredStream = new MemoryStream();
await inputStream.AesEncryptAsync(cipheredStream, key, iv);
using var decipheredStream = new MemoryStream();
await cipheredStream.AesDecryptAsync(decipheredStream, key, iv);
var key = new byte[] {/* key bytes */};
var cipheredBytes = await inputBytes.AesEncryptAsync(key);
var decipheredBytes = await cipheredBytes.AesDecryptAsync(key);