Early Preview

This is currently very much a preview. Please feel free to try things out, but don't be upset if anything is not yet working. Feedback is welcome over on our GitHub Dicussions page.

class System.​Security.​Cryptography.​CryptographicOperations

Assembly: System.Security.Cryptography

Inheritance: object → CryptographicOperations

Provides methods for common cryptographic operations and reducing side-channel information leakage.

Methods

public static bool
FixedTimeEquals​(ReadOnlySpan<​byte> left, ReadOnlySpan<​byte> right)
Determines the equality of two byte sequences in an amount of time that depends on the length of the sequences, but not their values.
Returns <see langword="true" /> if <paramref name="left" /> and <paramref name="right" /> have the same values for <see cref="P:System.ReadOnlySpan`1.Length" /> and the same contents; otherwise, <see langword="false" /> .
left The first buffer to compare.
right The second buffer to compare.
public static byte[]
HashData​(HashAlgorithmName hashAlgorithm, byte[] source)
Computes the hash of data.
Returns The hash of the data.
hashAlgorithm The algorithm used to compute the hash.
source The data to hash.
public static byte[]
HashData​(HashAlgorithmName hashAlgorithm, IO.​Stream source)
Computes the hash of a stream.
Returns The hash of the data.
hashAlgorithm The algorithm used to compute the hash.
source The stream to hash.
public static int
HashData​(HashAlgorithmName hashAlgorithm, IO.​Stream source, Span<​byte> destination)
Computes the hash of a stream.
Returns The total number of bytes written to <paramref name="destination" /> .
hashAlgorithm The algorithm used to compute the hash.
source The stream to hash.
destination The buffer to receive the hash value.
public static byte[]
HashData​(HashAlgorithmName hashAlgorithm, ReadOnlySpan<​byte> source)
Computes the hash of data.
Returns The hash of the data.
hashAlgorithm The algorithm used to compute the hash.
source The data to hash.
public static int
HashData​(HashAlgorithmName hashAlgorithm, ReadOnlySpan<​byte> source, Span<​byte> destination)
Computes the hash of data.
Returns The total number of bytes written to <paramref name="destination" /> .
hashAlgorithm The algorithm used to compute the hash.
source The data to hash.
destination The buffer to receive the hash value.
public static Threading.​Tasks.​ValueTask<​int>
HashDataAsync​(HashAlgorithmName hashAlgorithm, IO.​Stream source, Memory<​byte> destination, Threading.​CancellationToken cancellationToken = null)
Asynchronously computes the hash of a stream.
Returns The total number of bytes written to <paramref name="destination" /> .
hashAlgorithm The algorithm used to compute the hash.
source The stream to hash.
destination The buffer to receive the hash value.
cancellationToken The token to monitor for cancellation requests. The default value is <see cref="P:System.Threading.CancellationToken.None" /> .
public static Threading.​Tasks.​ValueTask<​byte[]>
HashDataAsync​(HashAlgorithmName hashAlgorithm, IO.​Stream source, Threading.​CancellationToken cancellationToken = null)
Asynchronously computes the hash of a stream.
Returns The hash of the data.
hashAlgorithm The algorithm used to compute the hash.
source The stream to hash.
cancellationToken The token to monitor for cancellation requests. The default value is <see cref="P:System.Threading.CancellationToken.None" /> .
public static byte[]
HmacData​(HashAlgorithmName hashAlgorithm, byte[] key, byte[] source)
Computes the HMAC of data.
Returns The HMAC of the data.
hashAlgorithm The algorithm used to compute the HMAC.
key The secret key. The key can be any length.
source The data to compute the HMAC over.
public static byte[]
HmacData​(HashAlgorithmName hashAlgorithm, byte[] key, IO.​Stream source)
Computes the HMAC of a stream.
Returns The HMAC of the data.
hashAlgorithm The algorithm used to compute the HMAC.
key The secret key. The key can be any length.
source The data to compute the HMAC over.
public static byte[]
HmacData​(HashAlgorithmName hashAlgorithm, ReadOnlySpan<​byte> key, IO.​Stream source)
Computes the HMAC of a stream.
Returns The HMAC of the data.
hashAlgorithm The algorithm used to compute the HMAC.
key The secret key. The key can be any length.
source The data to compute the HMAC over.
public static int
HmacData​(HashAlgorithmName hashAlgorithm, ReadOnlySpan<​byte> key, IO.​Stream source, Span<​byte> destination)
Computes the HMAC of a stream.
Returns The total number of bytes written to <paramref name="destination" /> .
hashAlgorithm The algorithm used to compute the HMAC.
key The secret key. The key can be any length.
source The data to compute the HMAC over.
destination The buffer to receive the HMAC value.
public static byte[]
HmacData​(HashAlgorithmName hashAlgorithm, ReadOnlySpan<​byte> key, ReadOnlySpan<​byte> source)
Computes the HMAC of data.
Returns The HMAC of the data.
hashAlgorithm The algorithm used to compute the HMAC.
key The secret key. The key can be any length.
source The data to compute the HMAC over.
public static int
HmacData​(HashAlgorithmName hashAlgorithm, ReadOnlySpan<​byte> key, ReadOnlySpan<​byte> source, Span<​byte> destination)
Computes the HMAC of data.
Returns The total number of bytes written to <paramref name="destination" /> .
hashAlgorithm The algorithm used to compute the HMAC.
key The secret key. The key can be any length.
source The data to compute the HMAC over.
destination The buffer to receive the HMAC value.
public static Threading.​Tasks.​ValueTask<​byte[]>
HmacDataAsync​(HashAlgorithmName hashAlgorithm, byte[] key, IO.​Stream source, Threading.​CancellationToken cancellationToken = null)
Asynchronously computes the HMAC of a stream.
Returns The HMAC of the data.
hashAlgorithm The algorithm used to compute the HMAC.
key The secret key. The key can be any length.
source The stream to compute the HMAC over.
cancellationToken The token to monitor for cancellation requests. The default value is <see cref="P:System.Threading.CancellationToken.None" /> .
public static Threading.​Tasks.​ValueTask<​int>
HmacDataAsync​(HashAlgorithmName hashAlgorithm, ReadOnlyMemory<​byte> key, IO.​Stream source, Memory<​byte> destination, Threading.​CancellationToken cancellationToken = null)
Asynchronously computes the HMAC of a stream.
Returns The total number of bytes written to <paramref name="destination" /> .
hashAlgorithm The algorithm used to compute the HMAC.
key The secret key. The key can be any length.
source The stream to compute the HMAC over.
destination The buffer to receive the HMAC value.
cancellationToken The token to monitor for cancellation requests. The default value is <see cref="P:System.Threading.CancellationToken.None" /> .
public static Threading.​Tasks.​ValueTask<​byte[]>
HmacDataAsync​(HashAlgorithmName hashAlgorithm, ReadOnlyMemory<​byte> key, IO.​Stream source, Threading.​CancellationToken cancellationToken = null)
Asynchronously computes the HMAC of a stream.
Returns The HMAC of the data.
hashAlgorithm The algorithm used to compute the HMAC.
key The secret key. The key can be any length.
source The stream to compute the HMAC over.
cancellationToken The token to monitor for cancellation requests. The default value is <see cref="P:System.Threading.CancellationToken.None" /> .
public static bool
TryHashData​(HashAlgorithmName hashAlgorithm, ReadOnlySpan<​byte> source, Span<​byte> destination, Int32& bytesWritten)
public static bool
TryHmacData​(HashAlgorithmName hashAlgorithm, ReadOnlySpan<​byte> key, ReadOnlySpan<​byte> source, Span<​byte> destination, Int32& bytesWritten)
public static void
ZeroMemory​(Span<​byte> buffer)
Fills the provided buffer with zeros.
buffer The buffer to fill with zeros.
public bool
Equals​(object obj)
Inherited from object
protected void
Finalize​()
Inherited from object
public int
GetHashCode​()
Inherited from object
public Type
GetType​()
Inherited from object
protected object
MemberwiseClone​()
Inherited from object
public string
ToString​()
Inherited from object