Пример #1
0
        public void EncryptAndDecryptEmptyString()
        {
            var plainText = string.Empty;
            var key       = L64.GenerateKey();

            var cipherText = L64.Encrypt(plainText, key);
            var decrypted  = L64.Decrypt(cipherText, key);

            Assert.That(plainText, Is.EqualTo(cipherText));

            Assert.That(plainText, Is.EqualTo(decrypted));
        }
Пример #2
0
        public void FailToDecryptWithWrongKey()
        {
            var plainText  = "Foo Bar";
            var key        = L64.GenerateKey();
            var invalidKey = L64.GenerateKey();

            Assert.That(key, Is.Not.EqualTo(invalidKey));

            var cipherText = L64.Encrypt(plainText, key);
            var decrypted  = L64.Decrypt(cipherText, invalidKey).Trim();

            Assert.That(plainText, Is.Not.EqualTo(decrypted));
        }
Пример #3
0
        public void EncryptAndDecryptSimpleString()
        {
            var plainText = "Hello, World!";
            var key       = L64.GenerateKey();

            var cipherText = L64.Encrypt(plainText, key);
            var decrypted  = L64.Decrypt(cipherText, key).Trim();

            Assert.That(plainText, Is.Not.EqualTo(cipherText));
            Assert.That(plainText, Is.Not.SameAs(cipherText));

            Assert.That(plainText, Is.EqualTo(decrypted));
            Assert.That(plainText, Is.Not.SameAs(decrypted));

            Assert.That(decrypted, Is.Not.EqualTo(cipherText));
            Assert.That(decrypted, Is.Not.SameAs(cipherText));
        }
Пример #4
0
 public void RejectInvalidTexts()
 {
     Assert.That(() => L64.Encrypt(null, null), Throws.ArgumentNullException.With.Property("ParamName").EqualTo("plaintext"));
     Assert.That(() => L64.Decrypt(null, null), Throws.ArgumentNullException.With.Property("ParamName").EqualTo("ciphertext"));
 }