public void Test_DecryptString_with_encryption_data_appended()
        {
            var appendEncryptionData = true;
            var aesDecryptionResult  = new AesDecryptionResult();
            var errorMessage         = "";

            var aesEncryptionResult = _aes128cbcHmacSha256.EncryptString(_testString, _password, appendEncryptionDataToOutput: appendEncryptionData);

            if (aesEncryptionResult.Success)
            {
                aesDecryptionResult = _aes128cbcHmacSha256.DecryptString(aesEncryptionResult.EncryptedDataBase64String, _password, hasEncryptionDataAppendedInInput: appendEncryptionData);

                if (!aesDecryptionResult.Success)
                {
                    errorMessage = aesDecryptionResult.Message;
                }
            }
            else
            {
                errorMessage = aesEncryptionResult.Message;
            }

            Assert.IsTrue((aesEncryptionResult.Success && aesDecryptionResult.Success && aesDecryptionResult.DecryptedDataString.Equals(_testString)), errorMessage);
        }
示例#2
0
        private void ValidLicenseKey(PersonAccessViewModel pModel)
        {
            string hostName             = Dns.GetHostName();
            string validKey             = ConfigurationManager.AppSettings["ValidKey"];
            var    _aes128cbcHmacSha256 = new AE_AES_128_CBC_HMAC_SHA_256();
            var    aesDecryptionResult  = _aes128cbcHmacSha256.DecryptString(validKey, _password, hasEncryptionDataAppendedInInput: true);

            if (!aesDecryptionResult.DecryptedDataString.Equals(hostName))
            {
                pModel.InvalidLicenseKey = "Invalid License Key.";
            }
            else
            {
                pModel.InvalidLicenseKey = string.Empty;
            }
        }