using NUnit.Framework; using System; using System.Security.Cryptography; using System.Text; namespace ServiceOutsideTests.Crypto { public class AES { [Test] public void EncryptPasswordShort32Length() { byte[] key = ServiceShared.Crypto.AES.GetKey("a"); string input = "Befundapp"; string encrypted = ServiceShared.Crypto.AES.Encrypt(input, key); string decrypted = ServiceShared.Crypto.AES.Decrypt(encrypted, key); Assert.AreEqual(input, decrypted); } [Test] public void EncryptPasswordLong32Length() { byte[] key = ServiceShared.Crypto.AES.GetKey("a dasdas djakl jdklas jdlkjakldhsajkdhsakdhkajhdkjgahkdgsagdas gdj sadag jdsaj gdg jasdagj dgsa gdsa dsga dgsja gdjagdgasj gjhdga gdja"); string input = "Hello World"; string encrypted = ServiceShared.Crypto.AES.Encrypt(input, key); string decrypted = ServiceShared.Crypto.AES.Decrypt(encrypted, key); Assert.AreEqual(input, decrypted); } [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); } } [Test] public void EncryptDecryptFixedValues() { string input = "Hello World"; string encrypted = "JWHs6itvC1ncFamZFGOl8npLNCZAP2Vg/9jUPfRK8ORH0kJxOYGW"; byte[] key = ServiceShared.Crypto.AES.GetKey("1"); string decrypted = ServiceShared.Crypto.AES.Decrypt(encrypted, key); Assert.AreEqual(input, decrypted); } } }