48 lines
1.3 KiB
C#
48 lines
1.3 KiB
C#
using System;
|
|
using System.Text;
|
|
using System.Collections.Generic;
|
|
using NUnit.Framework;
|
|
using System.Linq;
|
|
using Sarand.Net.Standard.Base.Data;
|
|
|
|
namespace Sacs.UnitTests.Net.Standard.Base.Data
|
|
{
|
|
[TestFixture]
|
|
public class SacsAesIvCrypter_Tester
|
|
{
|
|
// --- Data Members ---
|
|
|
|
private static Random random = new Random();
|
|
|
|
// --- Tests ---
|
|
|
|
[Test]
|
|
public void SacsAesIvCrypter_Test ()
|
|
{
|
|
for (int i = 0; i < 200; i++)
|
|
{
|
|
String data = RandomString(random.Next(10, 2048), true);
|
|
int dataLength = data.Length;
|
|
String key = RandomString(random.Next(10, 128), true);
|
|
int keyLength = key.Length;
|
|
String encrypted = SacsAesIvCrypter.Encrypt(data, key);
|
|
int encryptedLength = encrypted.Length;
|
|
Assert.That(SacsAesIvCrypter.Decrypt(encrypted, key), Is.EqualTo(data));
|
|
}
|
|
}
|
|
|
|
// --- Utilities ---
|
|
|
|
/// <summary>Generate random alphanumeric string</summary>
|
|
private static String RandomString (int length, bool includeLowerCase = true, bool includeSymbols = true)
|
|
{
|
|
String chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
|
if (includeLowerCase) chars += "abcdefghijklmnopqrstuvwxyz";
|
|
if (includeSymbols) chars += "`¬!\"£$%^&*()-=_+{}[];:'@#~<>?/.,\\| ";
|
|
return new string(Enumerable.Repeat(chars, length).Select(s => s[random.Next(s.Length)]).ToArray());
|
|
}
|
|
|
|
// --- The End ---
|
|
}
|
|
}
|