Ejemplo n.º 1
0
        [TestCase("Password", "18cKBWuDPW5jVXn580mAxEAouNkRbMXq392WfQ/QFNk=", "RbWZAwKpPx6zFLLuyubeR61i+QpLULw2kvHIGYrUYR4=")] // Used below. ensure it's normally valid
        public void EncryptThenDecrypt_DecryptsSuccessfully(string toEncrypt, string encryptionKey, string authenticationKey)
        {
            // Arrange
            var encryptionKeyBytes     = Convert.FromBase64String(encryptionKey);
            var authenticationKeyBytes = Convert.FromBase64String(authenticationKey);

            // Act
            string encrypted = AESThenHMACEncryptionHelper.SimpleEncrypt(toEncrypt, encryptionKeyBytes, authenticationKeyBytes);
            string decrypted = AESThenHMACEncryptionHelper.SimpleDecrypt(encrypted, encryptionKeyBytes, authenticationKeyBytes);

            // Assert
            Assert.AreEqual(toEncrypt, decrypted);
        }
Ejemplo n.º 2
0
        [TestCase("PmUtd9koxdSmhtJyy3pQqQEe8743cs7zDRDyGRt7i6k=", "PE6K9jw/KQMgHxpzUJpKuzlrIQxUZjzvCnVe2wMEheo=")] // Authentication key invalid
        public void EncryptThenDecrypt_WhereEncryptionKeyIsInvalid_DoesNotDecrypt(string encryptionKey, string authenticationKey)
        {
            // Arrange
            string toEncrypt              = "Password";
            var    encryptionKeyBytes     = Convert.FromBase64String(encryptionKey);
            var    authenticationKeyBytes = Convert.FromBase64String(authenticationKey);
            string encrypted              = AESThenHMACEncryptionHelper.SimpleEncrypt(toEncrypt, encryptionKeyBytes, authenticationKeyBytes);

            var deencryptionKey    = Convert.FromBase64String("8oI/pQNdEx6aWNATrKVsUH0gU3wW3j05furiqLFax5k=");
            var deauthentiationKey = Convert.FromBase64String("PE6K9jw/KQMgHxpzUJpKuzlrIQxUZjzvCnVe2wMEheo=");

            // Act
            // Assert
            Assert.Throws <CryptographicException>(() => AESThenHMACEncryptionHelper.SimpleDecrypt(encrypted, deencryptionKey, deauthentiationKey));
        }