/// <summary> /// Verifies the specified signature. /// </summary> /// <param name="algorithm">The <see cref="SignatureAlgorithm"/> to use. This must be the same algorithm used to sign the data.</param> /// <param name="data">The data corresponding to the signature.</param> /// <param name="signature">The signature to verify.</param> /// <param name="cancellationToken">A <see cref="CancellationToken"/> to cancel the operation.</param> /// <returns> /// The result of the verify operation. If the signature is valid the <see cref="VerifyResult.IsValid"/> property of the returned <see cref="VerifyResult"/> will be set to true. /// </returns> /// <exception cref="ArgumentException">The specified <paramref name="algorithm"/> does not match the key corresponding to the key identifier.</exception> /// <exception cref="ArgumentNullException"><paramref name="data"/> is null.</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 VerifyResult VerifyData(SignatureAlgorithm algorithm, Stream data, byte[] signature, CancellationToken cancellationToken = default) { Argument.AssertNotNull(data, nameof(data)); VerifyResult result = null; if (_provider.SupportsOperation(KeyOperation.Verify)) { byte[] digest = CryptographyClient.CreateDigest(algorithm, data); result = _provider.Verify(algorithm, digest, signature, cancellationToken); } return(result ?? throw LocalCryptographyProvider.CreateOperationNotSupported(nameof(KeyOperation.Verify))); }
/// <summary> /// Verifies the specified signature. /// </summary> /// <param name="algorithm">The <see cref="SignatureAlgorithm"/> to use. This must be the same algorithm used to sign the data.</param> /// <param name="data">The data corresponding to the signature.</param> /// <param name="signature">The signature to verify.</param> /// <param name="cancellationToken">A <see cref="CancellationToken"/> to cancel the operation.</param> /// <returns> /// The result of the verify operation. If the signature is valid the <see cref="VerifyResult.IsValid"/> property of the returned <see cref="VerifyResult"/> will be set to true. /// </returns> /// <exception cref="ArgumentException">The specified <paramref name="algorithm"/> does not match the key corresponding to the key identifier.</exception> /// <exception cref="ArgumentNullException"><paramref name="data"/> is null.</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 <VerifyResult> VerifyDataAsync(SignatureAlgorithm algorithm, byte[] data, byte[] signature, CancellationToken cancellationToken = default) { Argument.AssertNotNull(data, nameof(data)); VerifyResult result = null; if (_provider.SupportsOperation(KeyOperation.Verify)) { byte[] digest = CryptographyClient.CreateDigest(algorithm, data); result = await _provider.VerifyAsync(algorithm, digest, signature, cancellationToken).ConfigureAwait(false); } return(result ?? throw LocalCryptographyProvider.CreateOperationNotSupported(nameof(KeyOperation.Verify))); }