bunch of fixes

This commit is contained in:
TheXamlGuy
2024-05-02 20:58:12 +01:00
parent 7dfbb91762
commit 8d62f36931
17 changed files with 180 additions and 134 deletions
+28
View File
@@ -0,0 +1,28 @@
using System.Security.Cryptography;
namespace Toolkit.Foundation;
public class AesDecryptor :
IDecryptor
{
private const int IvSize = 16;
public byte[] Decrypt(byte[] cipher, byte[] key)
{
Span<byte> iv = cipher.AsSpan(0, IvSize);
ReadOnlySpan<byte> encryptedContent = cipher.AsSpan(IvSize);
using Aes aes = Aes.Create();
aes.Key = key;
aes.IV = iv.ToArray();
using MemoryStream memoryStream = new(encryptedContent.ToArray());
using ICryptoTransform decryptor = aes.CreateDecryptor(aes.Key, aes.IV);
using CryptoStream cryptoStream = new(memoryStream, decryptor, CryptoStreamMode.Read);
using MemoryStream resultStream = new();
cryptoStream.CopyTo(resultStream);
return resultStream.ToArray();
}
}