Exemple #1
0
 /// <summary>
 /// Encrypts the specified plaintext.
 /// </summary>
 /// <param name="algorithm">The <see cref="EncryptionAlgorithm"/> to use.</param>
 /// <param name="plaintext">The data to encrypt.</param>
 /// <param name="cancellationToken">A <see cref="CancellationToken"/> to cancel the operation.</param>
 /// <returns>
 /// The result of the encrypt operation. The returned <see cref="EncryptResult"/> contains the encrypted data
 /// along with all other information needed to decrypt it. This information should be stored with the encrypted data.
 /// </returns>
 /// <exception cref="ArgumentException">The specified <paramref name="algorithm"/> does not match the key corresponding to the key identifier.</exception>
 /// <exception cref="CryptographicException">The local cryptographic provider threw an exception.</exception>
 /// <exception cref="InvalidOperationException">The key is invalid for the current operation.</exception>
 /// <exception cref="NotSupportedException">The operation is not supported with the specified key.</exception>
 public virtual async Task <EncryptResult> EncryptAsync(EncryptionAlgorithm algorithm, byte[] plaintext, CancellationToken cancellationToken = default) =>
 await EncryptAsync(new EncryptOptions(algorithm, plaintext), cancellationToken).ConfigureAwait(false);
Exemple #2
0
 /// <summary>
 /// Decrypts the specified ciphertext.
 /// </summary>
 /// <param name="algorithm">The <see cref="EncryptionAlgorithm"/> to use.</param>
 /// <param name="ciphertext">The encrypted data to decrypt.</param>
 /// <param name="cancellationToken">A <see cref="CancellationToken"/> to cancel the operation.</param>
 /// <returns>
 /// The result of the decrypt operation. The returned <see cref="DecryptResult"/> contains the encrypted data
 /// along with information regarding the algorithm and key used to decrypt it.
 /// </returns>
 /// <exception cref="ArgumentException">The specified <paramref name="algorithm"/> does not match the key corresponding to the key identifier.</exception>
 /// <exception cref="CryptographicException">The local cryptographic provider threw an exception.</exception>
 /// <exception cref="InvalidOperationException">The key is invalid for the current operation.</exception>
 /// <exception cref="NotSupportedException">The operation is not supported with the specified key.</exception>
 public virtual async Task <DecryptResult> DecryptAsync(EncryptionAlgorithm algorithm, byte[] ciphertext, CancellationToken cancellationToken = default) =>
 await DecryptAsync(new DecryptOptions(algorithm, ciphertext), cancellationToken).ConfigureAwait(false);
Exemple #3
0
 /// <summary>
 /// Decrypts ciphertext.
 /// </summary>
 /// <param name="algorithm">The <see cref="EncryptionAlgorithm"/> to use.</param>
 /// <param name="ciphertext">The encrypted data to decrypt.</param>
 /// <param name="cancellationToken">A <see cref="CancellationToken"/> to cancel the operation.</param>
 /// <returns>
 /// The result of the decrypt operation. The returned <see cref="DecryptResult"/> contains the encrypted data
 /// along with information regarding the algorithm and key used to decrypt it.
 /// </returns>
 /// <exception cref="ArgumentException">The specified <paramref name="algorithm"/> does not match the key corresponding to the key identifier.</exception>
 /// <exception cref="CryptographicException">The local cryptographic provider threw an exception.</exception>
 /// <exception cref="InvalidOperationException">The key is invalid for the current operation.</exception>
 /// <exception cref="NotSupportedException">The operation is not supported with the specified key.</exception>
 public virtual DecryptResult Decrypt(EncryptionAlgorithm algorithm, byte[] ciphertext, CancellationToken cancellationToken = default) =>
 Decrypt(new DecryptOptions(algorithm, ciphertext), cancellationToken);
 async Task <DecryptResult> ICryptographyProvider.DecryptAsync(EncryptionAlgorithm algorithm, byte[] ciphertext, CancellationToken cancellationToken)
 {
     return(await DecryptAsync(algorithm, ciphertext, cancellationToken).ConfigureAwait(false));
 }
 DecryptResult ICryptographyProvider.Decrypt(EncryptionAlgorithm algorithm, byte[] ciphertext, CancellationToken cancellationToken)
 {
     return(Decrypt(algorithm, ciphertext, cancellationToken));
 }
Exemple #6
0
 public virtual EncryptResult Encrypt(EncryptionAlgorithm algorithm, byte[] plaintext, CancellationToken cancellationToken = default)
 {
     throw CreateOperationNotSupported(nameof(Encrypt));
 }
 EncryptResult ICryptographyProvider.Encrypt(EncryptionAlgorithm algorithm, byte[] plaintext, CancellationToken cancellationToken)
 {
     return(Encrypt(algorithm, plaintext, cancellationToken));
 }
 EncryptResult ICryptographyProvider.Encrypt(EncryptionAlgorithm algorithm, byte[] plaintext, byte[] iv, byte[] authenticationData, CancellationToken cancellationToken)
 {
     return(Encrypt(algorithm, plaintext, iv, authenticationData, cancellationToken));
 }
 DecryptResult ICryptographyProvider.Decrypt(EncryptionAlgorithm algorithm, byte[] ciphertext, byte[] iv, byte[] authenticationData, byte[] authenticationTag, CancellationToken cancellationToken)
 {
     return(Decrypt(algorithm, ciphertext, iv, authenticationData, authenticationTag, cancellationToken));
 }
Exemple #10
0
        public Task <EncryptResult> EncryptAsync(EncryptionAlgorithm algorithm, byte[] plaintext, byte[] iv, byte[] authenticationData, CancellationToken cancellationToken)
        {
            EncryptResult result = Encrypt(algorithm, plaintext, iv, authenticationData, cancellationToken);

            return(Task.FromResult(result));
        }
Exemple #11
0
        public Task <DecryptResult> DecryptAsync(EncryptionAlgorithm algorithm, byte[] ciphertext, byte[] iv, byte[] authenticationData, byte[] authenticationTag, CancellationToken cancellationToken)
        {
            DecryptResult result = Decrypt(algorithm, ciphertext, iv, authenticationData, authenticationTag, cancellationToken);

            return(Task.FromResult(result));
        }
Exemple #12
0
 public EncryptResult Encrypt(EncryptionAlgorithm algorithm, byte[] plaintext, byte[] iv, byte[] authenticationData, CancellationToken cancellationToken)
 {
     // TODO
     throw new NotImplementedException();
 }
 public virtual EncryptResult Encrypt(EncryptionAlgorithm algorithm, byte[] plaintext, byte[] iv = null, byte[] authenticationData = null, CancellationToken cancellationToken = default)
 {
     throw new NotSupportedException();
 }
Exemple #14
0
        public virtual Task <EncryptResult> EncryptAsync(EncryptionAlgorithm algorithm, byte[] plaintext, CancellationToken cancellationToken = default)
        {
            EncryptResult result = Encrypt(algorithm, plaintext, cancellationToken);

            return(Task.FromResult(result));
        }
Exemple #15
0
 /// <summary>
 /// Encrypts the specified plaintext.
 /// </summary>
 /// <param name="algorithm">The <see cref="EncryptionAlgorithm"/> to use.</param>
 /// <param name="plaintext">The data to encrypt.</param>
 /// <param name="cancellationToken">A <see cref="CancellationToken"/> to cancel the operation.</param>
 /// <returns>
 /// The result of the encrypt operation. The returned <see cref="EncryptResult"/> contains the encrypted data
 /// along with all other information needed to decrypt it. This information should be stored with the encrypted data.
 /// </returns>
 /// <exception cref="ArgumentException">The specified <paramref name="algorithm"/> does not match the key corresponding to the key identifier.</exception>
 /// <exception cref="CryptographicException">The local cryptographic provider threw an exception.</exception>
 /// <exception cref="InvalidOperationException">The key is invalid for the current operation.</exception>
 /// <exception cref="NotSupportedException">The operation is not supported with the specified key.</exception>
 public virtual EncryptResult Encrypt(EncryptionAlgorithm algorithm, byte[] plaintext, CancellationToken cancellationToken = default) =>
 Encrypt(new EncryptOptions(algorithm, plaintext), cancellationToken);
 async Task <EncryptResult> ICryptographyProvider.EncryptAsync(EncryptionAlgorithm algorithm, byte[] plaintext, CancellationToken cancellationToken)
 {
     return(await EncryptAsync(algorithm, plaintext, cancellationToken).ConfigureAwait(false));
 }
 internal EncryptParameters(EncryptionAlgorithm algorithm, byte[] plaintext) :
     this(algorithm, plaintext, null, null)
 {
 }
Exemple #18
0
        public virtual Task <DecryptResult> DecryptAsync(EncryptionAlgorithm algorithm, byte[] ciphertext, CancellationToken cancellationToken = default)
        {
            DecryptResult result = Decrypt(algorithm, ciphertext, cancellationToken);

            return(Task.FromResult(result));
        }