Exemple #1
0
 /// <summary>
 /// Decrypts the specified ciphertext.
 /// </summary>
 /// <param name="ciphertext">
 /// The ciphertext to decrypt.
 /// </param>
 /// <param name="key">
 /// The key derivation bits and algorithm specification used to transform the ciphertext.
 /// </param>
 /// <returns>
 /// The resulting plaintext object.
 /// </returns>
 /// <exception cref="SecurityException">
 /// An exception was raised during decryption or deserialization.
 /// </exception>
 public T Decrypt(Byte[] ciphertext, SecureSymmetricKey key)
 {
     try
     {
         using (var keyBuffer = key.DeriveKey())
         {
             return(Decrypt(ciphertext, keyBuffer, key.Algorithm));
         }
     }
     catch
     {
         throw new SecurityException("The decryption operation failed.");
     }
 }
Exemple #2
0
 /// <summary>
 /// Encrypts the specified plaintext object.
 /// </summary>
 /// <param name="plaintextObject">
 /// The plaintext object to encrypt.
 /// </param>
 /// <param name="key">
 /// The key derivation bits and algorithm specification used to transform the object.
 /// </param>
 /// <param name="initializationVector">
 /// An initialization vector with length greater than or equal to the block size for the specified cipher (extra bytes are
 /// ignored), or <see langword="null" /> to generate a random initialization vector.
 /// </param>
 /// <returns>
 /// The resulting ciphertext.
 /// </returns>
 /// <exception cref="SecurityException">
 /// An exception was raised during encryption or serialization.
 /// </exception>
 public Byte[] Encrypt(T plaintextObject, SecureSymmetricKey key, Byte[] initializationVector)
 {
     try
     {
         using (var keyBuffer = key.DeriveKey())
         {
             return(Encrypt(plaintextObject, keyBuffer, key.Algorithm, initializationVector));
         }
     }
     catch
     {
         throw new SecurityException("The encryption operation failed.");
     }
 }