Exemple #1
0
        public void EncryptDecryptTests(string plainText)
        {
            var encryptedResult = _encryptorDecryptor.Encrypt(plainText);
            var decryptedResult = _encryptorDecryptor.Decrypt(encryptedResult);

            Assert.AreEqual(plainText, decryptedResult);
        }
Exemple #2
0
        /// <summary>
        /// if property is marked as [RequiresEncryption] - return decrypted value
        /// or shout if something is wrong
        /// </summary>
        private static string ReadAndDecryptValue(MemberInfo propertyInfo, string valueToDecrypt)
        {
            try
            {
                //decrypt if property is marked with [RequiresEncryption]
                if (Attribute.IsDefined(propertyInfo, typeof(RequiresEncryptionAttribute)))
                {
                    return(EncryptorDecryptor.Decrypt(valueToDecrypt));
                }

                //no decryption was required
                return(valueToDecrypt);
            }
            catch (Exception ce)
            {
                throw new ApplicationException(string.Format("{0} [{1}] {2} {3} {4}",

                                                             "Most probably, property ", propertyInfo.Name, " was marked as [RequiresEncryption] was supplied in plain form.. see details below ",
                                                             Environment.NewLine, ce.Message));
            }
        }