/// <summary> /// Encrypts data into a cipher. /// </summary> /// <param name="key">The key to the data to be used as entropy, cannot be null but can be empty.</param> /// <param name="data">The data to encrypt, cannot be null but can be empty.</param> /// <returns>The resulting cipher, cannot be null but can be empty.</returns> /// <exception cref="ArgumentNullException">The key or data argument is null.</exception> /// <exception cref="CryptographicException">The encryption operation failed, probably due to malformed key.</exception> public byte[] Encrypt(string key, byte[] data) { if (key == null) { throw new ArgumentNullException("key"); } if (data == null) { throw new ArgumentNullException("data", string.Format(CultureInfo.InvariantCulture, "Object cannot be null for key {0}", key)); } using (RSACryptoServiceProvider algorithm = AsymmetricDataEncryptor.InstantiateAlgorithm(this.keyData)) { return(AsymmetricDataEncryptor.Encrypt(algorithm, data)); } }
/// <summary> /// Encrypts data into a cipher. /// </summary> /// <param name="key">The key to the data to be used as entropy, cannot be null but can be empty.</param> /// <param name="data">The data to encrypt, cannot be null but can be empty.</param> /// <returns>The resulting cipher, cannot be null but can be empty.</returns> /// <exception cref="ArgumentNullException">The key or data argument is null.</exception> /// <exception cref="CryptographicException">The encryption operation failed, probably due to malformed key.</exception> public byte[] Encrypt(string key, byte[] data) { if (key == null) { throw new ArgumentNullException("key"); } if (data == null) { throw new ArgumentNullException("data", 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.Encrypt(this.algorithm, data)); }