Enabled selection of cipher mode (defaults to CBC), added method to conveniently create AES SymmetricCryptoStream.

This commit is contained in:
Filip Strajnar 2024-09-30 21:40:23 +02:00
parent 458acfcd85
commit 1eb93d2f9a

View file

@ -4,13 +4,24 @@ namespace Proculite.Common.Security.Cryptography
{
public static class SimpleAes
{
public static Aes Create(byte[] key, byte[] iv)
public static Aes Create(byte[] key, byte[] iv, CipherMode cipherMode = CipherMode.CBC)
{
Aes aes = Aes.Create();
aes.IV = iv;
aes.Key = key;
aes.Mode = cipherMode;
return aes;
}
public static SymmetricCryptoStream CreateCryptoStream(
byte[] key,
byte[] iv,
CipherMode cipherMode = CipherMode.CBC
)
{
Aes aes = Create(key, iv, cipherMode);
return new SymmetricCryptoStream(aes);
}
}
}