MacAlgorithmProvider MacAlgorithmProvider MacAlgorithmProvider MacAlgorithmProvider Class

Represents a message authentication code (MAC). A MAC uses symmetric key cryptography to prevent message tampering. For more information, see MACs, hashes, and signatures.

Syntax

Declaration

public sealed class MacAlgorithmProviderpublic sealed class MacAlgorithmProviderPublic NotInheritable Class MacAlgorithmProvider

Remarks

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

  • HMAC_MD5
  • HMAC_SHA1
  • HMAC_SHA256
  • HMAC_SHA384
  • HMAC_SHA512
  • AES_CMAC

Examples

[!code-csharpShowMacAlgProviderClass]

Properties summary

Gets the name of the open MAC algorithm.

Gets the length, in bytes, of the message authentication code.

Methods summary

Creates a CryptographicHash object that supports incremental hash operations.

Creates a symmetric key that can be used to create the MAC value.

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

Properties

  • AlgorithmName
    AlgorithmName
    AlgorithmName
    AlgorithmName

    Gets the name of the open MAC algorithm.

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

    Property Value

    • string
      string
      string
      string

      Algorithm name.

    Remarks

    You must call the OpenAlgorithm(System.String) method before calling this property. The following algorithm names are supported:

  • MacLength
    MacLength
    MacLength
    MacLength

    Gets the length, in bytes, of the message authentication code.

    public uint MacLength { get; }public uint MacLength { get; }Public ReadOnly Property MacLength As uint

    Property Value

    • uint
      uint
      uint
      uint

      Number of bytes in the MAC.

    Remarks

    You should verify that the length of the computed HMAC equals the length supported by the specified algorithm. For more information, see the following example.

Methods

  • CreateHash(Windows.Storage.Streams.IBuffer)
    CreateHash(Windows.Storage.Streams.IBuffer)
    CreateHash(Windows.Storage.Streams.IBuffer)
    CreateHash(Windows.Storage.Streams.IBuffer)

    Creates a CryptographicHash object that supports incremental hash operations.

    public CryptographicHash CreateHash(Windows.Storage.Streams.IBuffer keyMaterial)public CryptographicHash CreateHash(Windows.Storage.Streams.IBuffer keyMaterial)Public Function CreateHash(keyMaterial As Windows.Storage.Streams.IBuffer) As CryptographicHash

    Parameters

    Returns

  • CreateKey(Windows.Storage.Streams.IBuffer)
    CreateKey(Windows.Storage.Streams.IBuffer)
    CreateKey(Windows.Storage.Streams.IBuffer)
    CreateKey(Windows.Storage.Streams.IBuffer)

    Creates a symmetric key that can be used to create the MAC value.

    public CryptographicKey CreateKey(Windows.Storage.Streams.IBuffer keyMaterial)public CryptographicKey CreateKey(Windows.Storage.Streams.IBuffer keyMaterial)Public Function CreateKey(keyMaterial As Windows.Storage.Streams.IBuffer) As CryptographicKey

    Parameters

    Returns

  • OpenAlgorithm(System.String)
    OpenAlgorithm(System.String)
    OpenAlgorithm(System.String)
    OpenAlgorithm(System.String)

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

    public static MacAlgorithmProvider OpenAlgorithm(System.String algorithm)public static MacAlgorithmProvider OpenAlgorithm(System.String algorithm)Public Static Function OpenAlgorithm(algorithm As System.String) As MacAlgorithmProvider

    Parameters

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

      Algorithm name.

    Returns

    Remarks

    The following algorithm names are supported for use in the MacAlgorithmProvider class:

Device family

Windows 10 (introduced v10.0.10240.0)

API contract

Windows.Foundation.UniversalApiContract (introduced v1)

Attributes

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

Details

Assembly

Windows.Security.Cryptography.Core.dll