public void DeriveKey_CreateCommonKeyAndEncryptString_Pass()
        {
            ECDiffieHellmanAgreement agreement;
            byte[] commonKey;
            byte[] iv;
            string messageFromBob = "Hello my friend, how are you?";
            string encrypted;
            string decrypted;

            using(var alice = new ECDiffieHellmanCipher<ECDiffieHellmanCng>())
            {
                agreement = alice.Agreement;
                using(var bob = new ECDiffieHellmanCipher<ECDiffieHellmanCng>(agreement))
                {
                    commonKey = alice.DeriveKey(bob.PublicKey);
                    using (var cipher = new SymmetricCipher<AesManaged>(commonKey, out iv))
                        encrypted = cipher.EncryptToString(messageFromBob);
                }

                using (var cipher = new SymmetricCipher<AesManaged>(commonKey, iv))
                    decrypted = cipher.DecryptToString(encrypted);
            }

            Assert.AreEqual(messageFromBob, decrypted);
        }
Exemplo n.º 2
0
        public void EncryptToString_AesEncryptToStringAndDecryptToString_Pass()
        {
            string plainText = "Encrypt me but don' forget me.";
            string encryptedText;
            string decryptedText;
            using(var cipher = new SymmetricCipher<AesManaged>("passwd", "mysalt1337"))
            {
                encryptedText = cipher.EncryptToString(plainText);
                decryptedText = cipher.DecryptToString(encryptedText);
            }

            Assert.AreEqual(plainText, decryptedText);
        }
Exemplo n.º 3
0
        public void AesBasicCipher1_SameInstance_ComparesOutput()
        {
            string plainText = "Encrypt me but don' forget me.";
            byte[] plaindata = Encoding.UTF8.GetBytes(plainText);
            string encryptedText;
            string decryptedText;
            using (var cipher = new SymmetricCipher<AesManaged>("passwd", "mysalt1337"))
            {
                encryptedText = cipher.EncryptToString(plaindata);
                decryptedText = cipher.DecryptToString(encryptedText);
            }

            Assert.AreEqual(plainText, decryptedText);
        }
Exemplo n.º 4
0
        public void ConstructorWithOutParams_InstantiateNewWithRandomSaltAndIV_Pass()
        {
            string passwd = "PassIWantt0youS3";
            string message = "This is my cool message, you fokkin w0t m8";
            string cipherMessage;
            string decrypted;
            byte[] salt;
            byte[] IV;
            using (var cipher = new SymmetricCipher<AesManaged>(passwd, out salt, out IV))
            {
                cipherMessage = cipher.EncryptToString(message);
            }

            using(var cipher = new SymmetricCipher<AesManaged>(passwd, salt, IV))
            {
                decrypted = cipher.DecryptToString(cipherMessage);
            }

            Assert.AreEqual(message, decrypted);
        }
Exemplo n.º 5
0
        public void DecryptToString_EncryptAndDecryptToString_Pass()
        {
            string plainText = "Encrypt me but don' forget me.";
            byte[] plaindata = Encoding.UTF8.GetBytes(plainText);
            byte[] encryptedText;
            string decryptedText;
            using (var cipher = new SymmetricCipher<AesManaged>("passwd", "mysalt1337"))
            {
                encryptedText = cipher.Encrypt(plaindata);
                decryptedText = cipher.DecryptToString(encryptedText);
            }

            Assert.AreEqual(plainText, decryptedText);
        }