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.​IncrementalHash
Assembly: System.Security.Cryptography
Inheritance: object → IncrementalHash
Implemented Interfaces
Provides support for computing a hash or HMAC value incrementally across several segments.
Properties
public
HashAlgorithmName
AlgorithmName
Get the name of the algorithm being performed.
public
int
HashLengthInBytes
Gets the output size of this hash or HMAC algorithm, in bytes.
Methods
public
void
AppendData​(byte[] data)
Append the entire contents of <paramref name="data" /> to the data already processed in the hash or HMAC.
data
The data to process.
public
void
AppendData​(byte[] data,
int offset,
int count)
Append <paramref name="count" /> bytes of <paramref name="data" /> , starting at <paramref name="offset" /> ,
to the data already processed in the hash or HMAC.
data
The data to process.
offset
The offset into the byte array from which to begin using data.
count
The number of bytes in the array to use as data.
public
void
AppendData​(ReadOnlySpan<​byte> data)
Appends the specified data to the data already processed in the hash or Hash-based Message Authentication Code (HMAC).
data
The data to process.
public
IncrementalHash
Clone​()
Creates a new instance of <see cref="T:System.Security.Cryptography.IncrementalHash" /> with the existing appended data preserved.
Returns A clone of the current instance.
public static
IncrementalHash
CreateHash​(HashAlgorithmName hashAlgorithm)
Create an <see cref="T:System.Security.Cryptography.IncrementalHash" /> for the algorithm specified by <paramref name="hashAlgorithm" /> .
Returns An <see cref="T:System.Security.Cryptography.IncrementalHash" /> instance ready to compute the hash algorithm specified
by <paramref name="hashAlgorithm" /> .
hashAlgorithm
The name of the hash algorithm to perform.
public static
IncrementalHash
CreateHMAC​(HashAlgorithmName hashAlgorithm,
byte[] key)
Create an <see cref="T:System.Security.Cryptography.IncrementalHash" /> for the Hash-based Message Authentication Code (HMAC)
algorithm utilizing the hash algorithm specified by <paramref name="hashAlgorithm" /> , and a
key specified by <paramref name="key" /> .
Returns An <see cref="T:System.Security.Cryptography.IncrementalHash" /> instance ready to compute the hash algorithm specified
by <paramref name="hashAlgorithm" /> .
hashAlgorithm
The name of the hash algorithm to perform within the HMAC.
key
The secret key for the HMAC. The key can be any length, but a key longer than the output size
of the hash algorithm specified by <paramref name="hashAlgorithm" /> will be hashed (using the
algorithm specified by <paramref name="hashAlgorithm" /> ) to derive a correctly-sized key. Therefore,
the recommended size of the secret key is the output size of the hash specified by
<paramref name="hashAlgorithm" /> .
public static
IncrementalHash
CreateHMAC​(HashAlgorithmName hashAlgorithm,
ReadOnlySpan<​byte> key)
Create an <see cref="T:System.Security.Cryptography.IncrementalHash" /> for the Hash-based Message Authentication Code (HMAC) algorithm utilizing the hash algorithm specified by <paramref name="hashAlgorithm" /> , and a key specified by <paramref name="key" /> .
Returns A hash instance to compute the hash algorithm specified by <paramref name="hashAlgorithm" /> .
hashAlgorithm
The name of the hash algorithm to perform within the HMAC.
key
The secret key for the HMAC.
public
void
Dispose​()
Release all resources used by the current instance of the
<see cref="T:System.Security.Cryptography.IncrementalHash" /> class.
public
byte[]
GetCurrentHash​()
Retrieves the hash or Hash-based Message Authentication Code (HMAC) for the data accumulated from prior calls to the <see cref="M:System.Security.Cryptography.IncrementalHash.AppendData(System.ReadOnlySpan{System.Byte})" /> methods, without resetting the object to its initial state.
Returns The computed hash or HMAC.
public
int
GetCurrentHash​(Span<​byte> destination)
Retrieves the hash or Hash-based Message Authentication Code (HMAC) for the data accumulated from prior calls to the <see cref="M:System.Security.Cryptography.IncrementalHash.AppendData(System.ReadOnlySpan{System.Byte})" /> methods, without resetting the object to its initial state.
Returns The number of bytes written to <paramref name="destination" /> .
destination
The buffer to receive the hash or HMAC value.
public
byte[]
GetHashAndReset​()
Retrieve the hash or HMAC for the data accumulated from prior calls to
<see cref="M:System.Security.Cryptography.IncrementalHash.AppendData(System.Byte[])" /> , and return to the state the object
was in at construction.
Returns The computed hash or HMAC.
public
int
GetHashAndReset​(Span<​byte> destination)
Retrieves the hash or Hash-based Message Authentication Code (HMAC) for the data accumulated from prior calls to the <see cref="M:System.Security.Cryptography.IncrementalHash.AppendData(System.ReadOnlySpan{System.Byte})" /> methods, and resets the object to its initial state.
Returns The number of bytes written to <paramref name="destination" /> .
destination
The buffer to receive the hash or HMAC value.
public
bool
TryGetCurrentHash​(Span<​byte> destination,
Int32& bytesWritten)
public
bool
TryGetHashAndReset​(Span<​byte> destination,
Int32& bytesWritten)
public
bool
Equals​(object obj)
Inherited from object
protected
void
Finalize​()
Inherited from object
public
int
GetHashCode​()
Inherited from object
protected
object
MemberwiseClone​()
Inherited from object
public
string
ToString​()
Inherited from object