예제 #1
0
        /// <summary>
        /// Decrypts a cipher into the original data.
        /// </summary>
        /// <param name="key">The key to the data to be used as entropy, cannot be null but can be empty.</param>
        /// <param name="cipher">The cipher to decrypt, cannot be null but can be empty.</param>
        /// <returns>The resulting data, cannot be null but can be empty.</returns>
        /// <exception cref="ArgumentNullException">The key or cipher argument is null.</exception>
        /// <exception cref="CryptographicException">The encryption operation failed, probably due to malformed key or key mismatch.</exception>
        public byte[] Decrypt(string key, byte[] cipher)
        {
            if (key == null)
            {
                throw new ArgumentNullException("key");
            }

            if (cipher == null)
            {
                throw new ArgumentNullException("cipher", string.Format(CultureInfo.InvariantCulture, "Object cannot be null for key {0}", key));
            }

            using (RSACryptoServiceProvider algorithm = AsymmetricDataEncryptor.InstantiateAlgorithm(this.keyData))
            {
                return(AsymmetricDataEncryptor.Decrypt(algorithm, cipher));
            }
        }
예제 #2
0
            /// <summary>
            /// Decrypts a cipher into the original data.
            /// </summary>
            /// <param name="key">The key to the data to be used as entropy, cannot be null but can be empty.</param>
            /// <param name="cipher">The cipher to decrypt, cannot be null but can be empty.</param>
            /// <returns>The resulting data, cannot be null but can be empty.</returns>
            /// <exception cref="ArgumentNullException">The key or cipher argument is null.</exception>
            /// <exception cref="CryptographicException">The encryption operation failed, probably due to malformed key or key mismatch.</exception>
            public byte[] Decrypt(string key, byte[] cipher)
            {
                if (key == null)
                {
                    throw new ArgumentNullException("key");
                }

                if (cipher == null)
                {
                    throw new ArgumentNullException("cipher", string.Format(CultureInfo.InvariantCulture, "Object cannot be null for key {0}", key));
                }

                if (this.disposed)
                {
                    throw new ObjectDisposedException("This instance has been disposed.");
                }

                return(AsymmetricDataEncryptor.Decrypt(this.algorithm, cipher));
            }