Пример #1
0
        public void ExpectValidDecryptionToSucceed()
        {
            var encryptionResult = SimpleAESEncryption.Encrypt(plaintext, password1);
            var decryptedText    = SimpleAESEncryption.Decrypt(encryptionResult, password1);

            Assert.AreEqual(plaintext, decryptedText);
        }
Пример #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));
        }
Пример #3
0
        public void ExpectValidEncryptionToSucceed()
        {
            var encryptionResult = SimpleAESEncryption.Encrypt(plaintext, password1);

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

            Assert.AreNotEqual(plaintext, encryptionResult.EncryptedText);
        }
Пример #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());
        }
Пример #5
0
        public void ExpectEmptyIVToFail()
        {
            var encryptionResult = SimpleAESEncryption.Encrypt(plaintext, password1);

            Assert.Throws <CryptographicException>(() =>
            {
                SimpleAESEncryption.Decrypt(encryptionResult.EncryptedText, string.Empty, password1);
            });
        }
Пример #6
0
        public void ExpectWrongPasswordToFail()
        {
            var encryptionResult = SimpleAESEncryption.Encrypt(plaintext, password1);

            Assert.Throws <CryptographicException>(() =>
            {
                SimpleAESEncryption.Decrypt(encryptionResult, password2);
            });
        }
Пример #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);
        }