HashAlgorithmProvider HashAlgorithmProvider HashAlgorithmProvider HashAlgorithmProvider Class

Represents a cryptographic hash provider. For more information about hashes, see MACs, hashes, and signatures.

Syntax

Declaration

public sealed class HashAlgorithmProviderpublic sealed class HashAlgorithmProviderPublic NotInheritable Class HashAlgorithmProviderpublic sealed class HashAlgorithmProvider

Remarks

You create a HashAlgorithmProvider object by calling the static OpenAlgorithm(String) method and specifying one of the following algorithm names:

  • MD5
  • SHA1
  • SHA256
  • SHA384
  • SHA512

Examples

[!code-csharpShowHashAlgProviderClass]

Properties summary

Gets the name of the open hash algorithm.

Gets the length, in bytes, of the hash.

Methods summary

Creates a reusable CryptographicHash object.

Hashes binary data.

Creates a HashAlgorithmProvider object and opens the specified algorithm for use.

Properties

  • AlgorithmName
    AlgorithmName
    AlgorithmName
    AlgorithmName

    Gets the name of the open hash algorithm.

    public string AlgorithmName { get; }public string AlgorithmName { get; }Public ReadOnly Property AlgorithmName As stringpublic string AlgorithmName { get; }

    Property Value

    • string
      string
      string
      string

      Algorithm name.

    Remarks

    The following hashing algorithm names are supported:

  • HashLength
    HashLength
    HashLength
    HashLength

    Gets the length, in bytes, of the hash.

    public uint HashLength { get; }public uint HashLength { get; }Public ReadOnly Property HashLength As uintpublic uint HashLength { get; }

    Property Value

    • uint
      uint
      uint
      uint

      Number of bytes in the hash.

    Remarks

    You should verify that the length of the hashed data equals the hash length supported by the specified algorithm. For more information, see the following code example.

Methods

  • CreateHash()
    CreateHash()
    CreateHash()
    CreateHash()

    Creates a reusable CryptographicHash object.

    public CryptographicHash CreateHash()public CryptographicHash CreateHash()Public Function CreateHash() As CryptographicHashpublic CryptographicHash CreateHash()

    Returns

    Remarks

    You must call the OpenAlgorithm(String) method before calling this property. Call the Append(IBuffer) method on the CryptographicHash object to copy hashed data into a buffer. Call the GetValueAndReset() method to retrieve the hashed data and reset the CryptographicHash object so that it can be used again to hash more data.

  • HashData(IBuffer)
    HashData(IBuffer)
    HashData(IBuffer)
    HashData(IBuffer)

    Hashes binary data.

    public IBuffer HashData(IBuffer data)public IBuffer HashData(IBuffer data)Public Function HashData(data As IBuffer) As IBufferpublic IBuffer HashData(IBuffer data)

    Parameters

    Returns

    Remarks

    See the CryptographicHash class for information about creating a reusable hashing object.

  • OpenAlgorithm(String)
    OpenAlgorithm(String)
    OpenAlgorithm(String)
    OpenAlgorithm(String)

    Creates a HashAlgorithmProvider object and opens the specified algorithm for use.

    public static HashAlgorithmProvider OpenAlgorithm(String algorithm)public static HashAlgorithmProvider OpenAlgorithm(String algorithm)Public Static Function OpenAlgorithm(algorithm As String) As HashAlgorithmProviderpublic static HashAlgorithmProvider OpenAlgorithm(String algorithm)

    Parameters

    • algorithm
      System.String
      System.String
      System.String
      System.String

      Algorithm name.

    Returns

    Remarks

    The following hashing algorithm names are supported:

Device family

Windows 10 (introduced v10.0.10240.0)

API contract

Windows.Foundation.UniversalApiContract (introduced v1)

Attributes

Windows.Foundation.Metadata.ContractVersionAttribute
Windows.Foundation.Metadata.DualApiPartitionAttribute
Windows.Foundation.Metadata.MarshalingBehaviorAttribute
Windows.Foundation.Metadata.StaticAttribute
Windows.Foundation.Metadata.ThreadingAttribute

Details

Assembly

Windows.Security.Cryptography.Core.dll