patbef-ServiceOutside/ServiceOutside/Documents/Datenschutz-Audit/Crypto_Codes_with_Unittests/UnitTests/AES.txt

30 lines
944 B
Plaintext
Raw Permalink Normal View History

2024-01-29 16:27:34 +01:00
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
namespace ServiceOutsideTests.Crypto
{
public class AES
{
[Test]
public void EncryptDecrypt()
{
for(int i = 0; i < 1000; i++)
{
int KeySize = new Random().Next(1, 4096);
byte[] random = new byte[KeySize];
RandomNumberGenerator.Fill(random);
string key = Encoding.UTF8.GetString(random);
string input = "Hello World";
string encrypted = ServiceShared.Crypto.AES.Encrypt(input, ServiceShared.Crypto.AES.GetKey(key));
string decrypted = ServiceShared.Crypto.AES.Decrypt(encrypted, ServiceShared.Crypto.AES.GetKey(key));
Assert.AreEqual(input, decrypted);
}
}
}
}