コード例 #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 ExpectEmptyIVToFail()
        {
            var encryptionResult = SimpleAESEncryption.Encrypt(plaintext, password1);

            Assert.Throws <CryptographicException>(() =>
            {
                SimpleAESEncryption.Decrypt(encryptionResult.EncryptedText, string.Empty, password1);
            });
        }
コード例 #3
0
        public void ExpectWrongPasswordToFail()
        {
            var encryptionResult = SimpleAESEncryption.Encrypt(plaintext, password1);

            Assert.Throws <CryptographicException>(() =>
            {
                SimpleAESEncryption.Decrypt(encryptionResult, password2);
            });
        }
コード例 #4
0
        public override void FromJson(string json)
        {
            JSONNode rootNode = JSONNode.Parse(json);

            if (rootNode["json"].IsString && rootNode["password"].IsString)
            {
                var decryptedJson = SimpleAESEncryption.Decrypt(rootNode["json"].Value, rootNode["password"].Value, EncryptionKey);
                JsonUtility.FromJsonOverwrite(decryptedJson, this);
            }
        }
コード例 #5
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);
        }