public void ExpectValidDecryptionToSucceed() { var encryptionResult = SimpleAESEncryption.Encrypt(plaintext, password1); var decryptedText = SimpleAESEncryption.Decrypt(encryptionResult, password1); Assert.AreEqual(plaintext, decryptedText); }
public void ExpectEmptyIVToFail() { var encryptionResult = SimpleAESEncryption.Encrypt(plaintext, password1); Assert.Throws <CryptographicException>(() => { SimpleAESEncryption.Decrypt(encryptionResult.EncryptedText, string.Empty, password1); }); }
public void ExpectWrongPasswordToFail() { var encryptionResult = SimpleAESEncryption.Encrypt(plaintext, password1); Assert.Throws <CryptographicException>(() => { SimpleAESEncryption.Decrypt(encryptionResult, password2); }); }
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); } }
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); }