public void TestAes200_Bytes() { int length = 100; var rand = new RandomGenerator(); //byte[] entropy = new byte[20]; for (int i = 0; i < length; i++) { byte[] newKey = new byte[rand.RandomNumber(75, 88)]; using (var rng = new RNGCryptoServiceProvider()) { //rng.GetBytes(entropy); rng.GetBytes(newKey); } var stringToEncrypt = Guid.NewGuid().ToString("N") + ":* d’une secrétairE chargée des affaires des étudiants de la section"; var bytes = System.Text.Encoding.UTF8.GetBytes(stringToEncrypt); // base 64 var encryptedBytes = AesEncryptor.Encrypt200(bytes, newKey); var decryptedBytes = AesEncryptor.Decrypt(encryptedBytes, newKey); Assert.IsTrue(decryptedBytes.SequenceEqual(bytes)); var decryptedString = System.Text.Encoding.UTF8.GetString(decryptedBytes); Assert.AreEqual(stringToEncrypt, decryptedString); } }
public void TestAes200() { int length = 100; var rand = new RandomGenerator(); for (int i = 0; i < length; i++) { using (var password = rand.RandomSecureStringPassword(10, 50)) { var stringToEncrypt = Guid.NewGuid().ToString("N") + ":* d’une secrétairE chargée des affaires des étudiants de la section"; // base 64 var encryptedBase64 = AesEncryptor.Encrypt200(stringToEncrypt, password); var decryptedBase64 = AesEncryptor.Decrypt(encryptedBase64, password); Assert.AreEqual(stringToEncrypt, decryptedBase64); // base 36 var encryptedBase36 = AesEncryptor.Encrypt200(stringToEncrypt, password, true); var decryptedBase36 = AesEncryptor.Decrypt(encryptedBase36, password, true); Assert.AreEqual(stringToEncrypt, decryptedBase36); } } }