/// <summary>
        /// Intercepts a method and after invocation checks to see if the request implements ICacheable
        /// if so, the ICacheItemInvalidator is invoked to remove the item from the cache
        /// </summary>
        public virtual void Intercept(IInvocation invocation)
        {
            ArgumentValidation.ComponentNotNull(_cacheInvalidator);

            invocation.Proceed();

            _cacheInvalidator.Invalidate(invocation.ReturnValue as ICacheInvalidation);
        }
Пример #2
0
        /// <summary>
        /// Encrypts the specified input.
        /// </summary>
        /// <param name="input">The input.</param>
        /// <returns></returns>
        public string Encrypt(string input)
        {
            ArgumentValidation.ComponentNotNull(_passwordLocator);

            if (input.IsNullOrEmpty())
            {
                return(string.Empty);
            }

            Rijndael rinedal = null;

            byte[] plainText = null;
            string base64Encoded;

            try
            {
                string password = _passwordLocator.Locate();

                //get the ASCII bytes for the input
                plainText = Encoding.ASCII.GetBytes(input);

                //create the password derived bytes used to generate the key and IV values
                Rfc2898DeriveBytes pdb = new Rfc2898DeriveBytes(password, GenerateSalt(password));

                //Instantiate the Rijndael symmetric algorithm
                rinedal         = Rijndael.Create();
                rinedal.Padding = PaddingMode.ISO10126;
                rinedal.KeySize = 256;

                //create the encryptor
                ICryptoTransform cryptoTransform = rinedal.CreateEncryptor(pdb.GetBytes(32), pdb.GetBytes(16));

                //encrypt and encode to Base64
                base64Encoded = Convert.ToBase64String(cryptoTransform.TransformFinalBlock(plainText, 0, plainText.Length));
            }
            finally
            {
                // this clears out any secret data
                if (rinedal != null)
                {
                    rinedal.Clear();
                }

                // zeroes out our array
                if (plainText != null)
                {
                    for (int i = 0; i < plainText.Length; i++)
                    {
                        plainText[i] = 0;
                    }
                }
            }

            return(base64Encoded);
        }
Пример #3
0
        public void Invalidate(ICacheInvalidation cacheInvalidator)
        {
            if (cacheInvalidator == null || cacheInvalidator.IgnoreCache)
            {
                return;
            }

            ArgumentValidation.ComponentNotNull(_cacheConfiguration);

            foreach (var item in cacheInvalidator.Items)
            {
                InvalidateItem(item);
            }
        }
Пример #4
0
        /// <summary>
        /// Decrypts the specified input.
        /// </summary>
        /// <param name="input">The input.</param>
        /// <returns></returns>
        public string Decrypt(string input)
        {
            ArgumentValidation.ComponentNotNull(_passwordLocator);

            if (input.IsNullOrEmpty())
            {
                return(string.Empty);
            }

            Rijndael rinedal = null;

            byte[] cipherText = Convert.FromBase64String(input);
            byte[] plainText;

            try
            {
                string password = _passwordLocator.Locate();

                //create the password derived bytes used to generate the key and IV values
                Rfc2898DeriveBytes pdb = new Rfc2898DeriveBytes(password, GenerateSalt(password));

                //Instantiate the Rijndael symmetric algorithm
                rinedal         = Rijndael.Create();
                rinedal.Padding = PaddingMode.ISO10126;

                //create the Decryptor
                ICryptoTransform cryptoTransform = rinedal.CreateDecryptor(pdb.GetBytes(32), pdb.GetBytes(16));

                //Decrypt
                plainText = cryptoTransform.TransformFinalBlock(cipherText, 0, cipherText.Length);
            }
            finally
            {
                if (rinedal != null)
                {
                    rinedal.Clear();
                }
            }

            return(Encoding.ASCII.GetString(plainText));
        }