private byte[] DecryptAgileFromKey(EncryptionInfoAgile.EncryptionKeyData encr, byte[] key, byte[] encryptedData, long size, byte[] iv)
        {
            SymmetricAlgorithm decryptKey = GetEncryptionAlgorithm(encr);

            decryptKey.BlockSize = encr.BlockSize << 3;
            decryptKey.KeySize   = encr.KeyBits;
#if (Core)
            decryptKey.Mode = CipherMode.CBC;
#else
            decryptKey.Mode = encr.CipherChaining == eChainingMode.ChainingModeCBC ? CipherMode.CBC : CipherMode.CFB;
#endif
            decryptKey.Padding = PaddingMode.Zeros;

            ICryptoTransform decryptor = decryptKey.CreateDecryptor(
                FixHashSize(key, encr.KeyBits / 8),
                FixHashSize(iv, encr.BlockSize, 0x36));


            MemoryStream dataStream = new MemoryStream(encryptedData);

            CryptoStream cryptoStream = new CryptoStream(dataStream,
                                                         decryptor,
                                                         CryptoStreamMode.Read);

            var decryptedData = new byte[size];

            cryptoStream.Read(decryptedData, 0, (int)size);
            return(decryptedData);
        }
        private HashAlgorithm GetHashProvider(EncryptionInfoAgile.EncryptionKeyData encr)
        {
            switch (encr.HashAlgorithm)
            {
            case eHashAlogorithm.MD5:
                return(MD5.Create());

            //case eHashAlogorithm.RIPEMD160:
            //    return new RIPEMD160Managed();
            case eHashAlogorithm.SHA1:
                return(SHA1.Create());

            case eHashAlogorithm.SHA256:
                return(SHA256.Create());

            case eHashAlogorithm.SHA384:
                return(SHA384.Create());

            case eHashAlogorithm.SHA512:
                return(SHA512.Create());

            default:
                throw new NotSupportedException(string.Format("Hash provider is unsupported. {0}", encr.HashAlgorithm));
            }
        }
        private HashAlgorithm GetHashProvider(EncryptionInfoAgile.EncryptionKeyData encr)
        {
            switch (encr.HashAlgorithm)
            {
            case eHashAlogorithm.MD5:
                return(new MD5CryptoServiceProvider());

            case eHashAlogorithm.RIPEMD160:
                return(new RIPEMD160Managed());

            case eHashAlogorithm.SHA1:
                return(new SHA1CryptoServiceProvider());

            case eHashAlogorithm.SHA256:
                return(new SHA256CryptoServiceProvider());

            case eHashAlogorithm.SHA384:
                return(new SHA384CryptoServiceProvider());

            case eHashAlogorithm.SHA512:
                return(new SHA512CryptoServiceProvider());

            default:
                throw new NotSupportedException(string.Format("Hash provider is unsupported. {0}", encr.HashAlgorithm));
            }
        }
        private HMAC GetHmacProvider(EncryptionInfoAgile.EncryptionKeyData ei, byte[] salt)
        {
            switch (ei.HashAlgorithm)
            {
#if (!Core)
            case eHashAlogorithm.RIPEMD160:
                return(new HMACRIPEMD160(salt));
#endif
            case eHashAlogorithm.MD5:
                return(new HMACMD5(salt));

            case eHashAlogorithm.SHA1:
                return(new HMACSHA1(salt));

            case eHashAlogorithm.SHA256:
                return(new HMACSHA256(salt));

            case eHashAlogorithm.SHA384:
                return(new HMACSHA384(salt));

            case eHashAlogorithm.SHA512:
                return(new HMACSHA512(salt));

            default:
                throw(new NotSupportedException(string.Format("Hash method {0} not supported.", ei.HashAlgorithm)));
            }
        }
        private SymmetricAlgorithm GetEncryptionAlgorithm(EncryptionInfoAgile.EncryptionKeyData encr)
        {
            switch (encr.CipherAlgorithm)
            {
            case eCipherAlgorithm.AES:
                return(Aes.Create());

            //case eCipherAlgorithm.DES:
            //    return new DESCryptoServiceProvider();
            case eCipherAlgorithm.TRIPLE_DES:
            case eCipherAlgorithm.TRIPLE_DES_112:
                return(TripleDES.Create());

            //case eCipherAlgorithm.RC2:
            //    return new RC2CryptoServiceProvider();
            default:
                throw(new NotSupportedException(string.Format("Unsupported Cipher Algorithm: {0}", encr.CipherAlgorithm.ToString())));
            }
        }