public void TestRandomString(int?numChars) { string passphrase = Guid.NewGuid().ToString("N"); string input = null; if (numChars.HasValue) { input = GetRandomString(numChars.Value, numChars.Value); } byte[] encrypted; string decrypted; using (var algorithm = new Symmetric_AES_CBC_Passphrase()) { encrypted = algorithm.EncryptString(input, passphrase); } using (var algorithm = new Symmetric_AES_CBC_Passphrase()) { decrypted = algorithm.DecryptBytes(encrypted, passphrase).AsString(); } if (input == null) { Assert.IsNull(encrypted, "encrypted"); Assert.IsNull(decrypted, "decrypted"); } else { Assert.IsTrue(encrypted.Length >= input.Length, "encrypted.Length"); Assert.IsTrue(decrypted.SequenceEqual(input), "Decrypted does not match original."); } }
public void TestUnicodeString() { string passphrase = Guid.NewGuid().ToString("N"); string input = Convert.ToBase64String(SecureRandomizer.GetRandomBytes(100)) + "\u01e2\u01f0\u020e\u0229"; byte[] encrypted; string decrypted; using (var algorithm = new Symmetric_AES_CBC_Passphrase()) { encrypted = algorithm.EncryptString(input, passphrase); } using (var algorithm = new Symmetric_AES_CBC_Passphrase()) { Assert.IsTrue(encrypted.Length > 100, "encrypted.Length"); decrypted = algorithm.DecryptBytes(encrypted, passphrase).AsString(); } Assert.AreEqual(input, decrypted, string.Format("{0} | {1}", input, decrypted)); }