Esempio n. 1
0
        public void ExpectValidDecryptionToSucceed()
        {
            var encryptionResult = SimpleAESEncryption.Encrypt(plaintext, password1);
            var decryptedText    = SimpleAESEncryption.Decrypt(encryptionResult, password1);

            Assert.AreEqual(plaintext, decryptedText);
        }
Esempio n. 2
0
        public void ExpectEmptyInputsToProduceValidEncryption()
        {
            var encryptionResult = SimpleAESEncryption.Encrypt(string.Empty, string.Empty);

            Assert.IsTrue(!string.IsNullOrEmpty(encryptionResult.IV));
            Assert.IsTrue(!string.IsNullOrEmpty(encryptionResult.EncryptedText));
        }
Esempio n. 3
0
        public void ExpectValidEncryptionToSucceed()
        {
            var encryptionResult = SimpleAESEncryption.Encrypt(plaintext, password1);

            Assert.IsTrue(!string.IsNullOrEmpty(encryptionResult.EncryptedText));

            Assert.AreNotEqual(plaintext, encryptionResult.EncryptedText);
        }
Esempio n. 4
0
        public override string GetJson()
        {
            var      encrypted = SimpleAESEncryption.Encrypt(JsonUtility.ToJson(this), EncryptionKey);
            JSONNode rootNode  = new JSONObject();

            rootNode["json"]     = encrypted.EncryptedText;
            rootNode["password"] = encrypted.IV;
            return(rootNode.ToString());
        }
Esempio n. 5
0
        public void ExpectEmptyIVToFail()
        {
            var encryptionResult = SimpleAESEncryption.Encrypt(plaintext, password1);

            Assert.Throws <CryptographicException>(() =>
            {
                SimpleAESEncryption.Decrypt(encryptionResult.EncryptedText, string.Empty, password1);
            });
        }
Esempio n. 6
0
        public void ExpectWrongPasswordToFail()
        {
            var encryptionResult = SimpleAESEncryption.Encrypt(plaintext, password1);

            Assert.Throws <CryptographicException>(() =>
            {
                SimpleAESEncryption.Decrypt(encryptionResult, password2);
            });
        }
Esempio n. 7
0
        public void ExpectWrongIVToFail()
        {
            var encryptionResult = SimpleAESEncryption.Encrypt(plaintext, password1);
            var decryptedText    = SimpleAESEncryption.Decrypt(encryptionResult.EncryptedText, exampleValidIV, password1);

            Assert.IsTrue(!string.IsNullOrEmpty(encryptionResult.EncryptedText));

            Assert.AreNotEqual(plaintext, encryptionResult.EncryptedText);
            Assert.AreNotEqual(plaintext, decryptedText);
        }