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.​KeyedHashAlgorithm
Assembly: System.Security.Cryptography
Inheritance: object → HashAlgorithm → KeyedHashAlgorithm
Implemented Interfaces
- ICryptoTransform (Inherits: IDisposable) Implemented by: HashAlgorithm
Represents the abstract class from which all implementations of keyed hash algorithms must derive.
Fields and Constants
protected
byte[]
KeyValue
The key to use in the hash algorithm.
protected
int
HashSizeValue
Represents the size, in bits, of the computed hash code.
protected
int
State
Represents the state of the hash computation.
Properties
public
byte[]
Key
Gets or sets the key to use in the hash algorithm.
public
bool
CanReuseTransform
Gets a value indicating whether the current transform can be reused.
public
bool
CanTransformMultipleBlocks
When overridden in a derived class, gets a value indicating whether multiple blocks can be transformed.
public
byte[]
Hash
Gets the value of the computed hash code.
public
int
HashSize
Gets the size, in bits, of the computed hash code.
public
int
InputBlockSize
When overridden in a derived class, gets the input block size.
public
int
OutputBlockSize
When overridden in a derived class, gets the output block size.
Methods
public static
KeyedHashAlgorithm
Create​()
Creates an instance of the default implementation of a keyed hash algorithm.
Returns A new <see cref="T:System.Security.Cryptography.HMACSHA1" /> instance, unless the default settings have been changed.
public static
KeyedHashAlgorithm
Create​(string algName)
Creates an instance of the specified implementation of a keyed hash algorithm.
Returns A new instance of the specified keyed hash algorithm.
algName
The keyed hash algorithm implementation to use. The following table shows the valid values for the <paramref name="algName" /> parameter and the algorithms they map to.
<list type="table">
<listheader>
<term> Parameter value</term>
<description> Implements</description>
</listheader>
<item>
<term> System.Security.Cryptography.HMAC</term>
<description>
<see cref="T:System.Security.Cryptography.HMACSHA1" />
</description>
</item>
<item>
<term> System.Security.Cryptography.KeyedHashAlgorithm</term>
<description>
<see cref="T:System.Security.Cryptography.HMACSHA1" />
</description>
</item>
<item>
<term> HMACMD5</term>
<description>
<see cref="T:System.Security.Cryptography.HMACMD5" />
</description>
</item>
<item>
<term> System.Security.Cryptography.HMACMD5</term>
<description>
<see cref="T:System.Security.Cryptography.HMACMD5" />
</description>
</item>
<item>
<term> HMACRIPEMD160</term>
<description>
<see cref="T:System.Security.Cryptography.HMACRIPEMD160" />
</description>
</item>
<item>
<term> System.Security.Cryptography.HMACRIPEMD160</term>
<description>
<see cref="T:System.Security.Cryptography.HMACRIPEMD160" />
</description>
</item>
<item>
<term> HMACSHA1</term>
<description>
<see cref="T:System.Security.Cryptography.HMACSHA1" />
</description>
</item>
<item>
<term> System.Security.Cryptography.HMACSHA1</term>
<description>
<see cref="T:System.Security.Cryptography.HMACSHA1" />
</description>
</item>
<item>
<term> HMACSHA256</term>
<description>
<see cref="T:System.Security.Cryptography.HMACSHA256" />
</description>
</item>
<item>
<term> System.Security.Cryptography.HMACSHA256</term>
<description>
<see cref="T:System.Security.Cryptography.HMACSHA256" />
</description>
</item>
<item>
<term> HMACSHA384</term>
<description>
<see cref="T:System.Security.Cryptography.HMACSHA384" />
</description>
</item>
<item>
<term> System.Security.Cryptography.HMACSHA384</term>
<description>
<see cref="T:System.Security.Cryptography.HMACSHA384" />
</description>
</item>
<item>
<term> HMACSHA512</term>
<description>
<see cref="T:System.Security.Cryptography.HMACSHA512" />
</description>
</item>
<item>
<term> System.Security.Cryptography.HMACSHA512</term>
<description>
<see cref="T:System.Security.Cryptography.HMACSHA512" />
</description>
</item>
<item>
<term> MACTripleDES</term>
<description>
<see cref="T:System.Security.Cryptography.MACTripleDES" />
</description>
</item>
<item>
<term> System.Security.Cryptography.MACTripleDES</term>
<description>
<see cref="T:System.Security.Cryptography.MACTripleDES" />
</description>
</item>
</list>
protected
void
Dispose​(bool disposing)
Releases the unmanaged resources used by the <see cref="T:System.Security.Cryptography.KeyedHashAlgorithm" /> and optionally releases the managed resources.
disposing
<see langword="true" /> to release both managed and unmanaged resources; <see langword="false" /> to release only unmanaged resources.
public
void
Clear​()
Inherited from HashAlgorithm
Releases all resources used by the <see cref="T:System.Security.Cryptography.HashAlgorithm" /> class.
public
byte[]
ComputeHash​(byte[] buffer)
Inherited from HashAlgorithm
Computes the hash value for the specified byte array.
Returns The computed hash code.
buffer
The input to compute the hash code for.
public
byte[]
ComputeHash​(byte[] buffer,
int offset,
int count)
Inherited from HashAlgorithm
Computes the hash value for the specified region of the specified byte array.
Returns The computed hash code.
buffer
The input to compute the hash code for.
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
byte[]
ComputeHash​(IO.​Stream inputStream)
Inherited from HashAlgorithm
Computes the hash value for the specified <see cref="T:System.IO.Stream" /> object.
Returns The computed hash code.
inputStream
The input to compute the hash code for.
public
Threading.​Tasks.​Task<​byte[]>
ComputeHashAsync​(IO.​Stream inputStream,
Threading.​CancellationToken cancellationToken = null)
Inherited from HashAlgorithm
Asynchronously computes the hash value for the specified <see cref="T:System.IO.Stream" /> object.
Returns A task that represents the asynchronous compute hash operation and wraps the computed hash code.
inputStream
The input to compute the hash code for.
cancellationToken
The token to monitor for cancellation requests.
public
void
Dispose​()
Inherited from HashAlgorithm
Releases all resources used by the current instance of the <see cref="T:System.Security.Cryptography.HashAlgorithm" /> class.
protected
void
HashCore​(byte[] array,
int ibStart,
int cbSize)
Inherited from HashAlgorithm
When overridden in a derived class, routes data written to the object into the hash algorithm for computing the hash.
array
The input to compute the hash code for.
ibStart
The offset into the byte array from which to begin using data.
cbSize
The number of bytes in the byte array to use as data.
protected
void
HashCore​(ReadOnlySpan<​byte> source)
Inherited from HashAlgorithm
Routes data written to the object into the hash algorithm for computing the hash.
source
The input to compute the hash code for.
protected
byte[]
HashFinal​()
Inherited from HashAlgorithm
When overridden in a derived class, finalizes the hash computation after the last data is processed by the cryptographic hash algorithm.
Returns The computed hash code.
public
void
Initialize​()
Inherited from HashAlgorithm
Resets the hash algorithm to its initial state.
public
int
TransformBlock​(byte[] inputBuffer,
int inputOffset,
int inputCount,
byte[] outputBuffer,
int outputOffset)
Inherited from HashAlgorithm
Computes the hash value for the specified region of the input byte array and copies the specified region of the input byte array to the specified region of the output byte array.
Returns The number of bytes written.
inputBuffer
The input to compute the hash code for.
inputOffset
The offset into the input byte array from which to begin using data.
inputCount
The number of bytes in the input byte array to use as data.
outputBuffer
A copy of the part of the input array used to compute the hash code.
outputOffset
The offset into the output byte array from which to begin writing data.
public
byte[]
TransformFinalBlock​(byte[] inputBuffer,
int inputOffset,
int inputCount)
Inherited from HashAlgorithm
Computes the hash value for the specified region of the specified byte array.
Returns An array that is a copy of the part of the input that is hashed.
inputBuffer
The input to compute the hash code for.
inputOffset
The offset into the byte array from which to begin using data.
inputCount
The number of bytes in the byte array to use as data.
public
bool
TryComputeHash​(ReadOnlySpan<​byte> source,
Span<​byte> destination,
Int32& bytesWritten)
Inherited from HashAlgorithm
protected
bool
TryHashFinal​(Span<​byte> destination,
Int32& bytesWritten)
Inherited from HashAlgorithm
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