Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

MacAlgorithmProvider.MacLength | macLength property

Applies to Windows and Windows Phone

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

Syntax


var macLength = macAlgorithmProvider.macLength;

Property value

Type: Number [JavaScript] | System.UInt32 [.NET] | uint32 [C++]

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.

Examples


void CreateHMAC(
    String strMsg,
    String strAlgName,
    out IBuffer buffMsg,
    out CryptographicKey hmacKey,
    out IBuffer buffHMAC)
{
    // Create a MacAlgorithmProvider object for the specified algorithm.
    MacAlgorithmProvider objMacProv = MacAlgorithmProvider.OpenAlgorithm(strAlgName);

    // Demonstrate how to retrieve the name of the algorithm used.
    String strNameUsed = objMacProv.AlgorithmName;

    // Create a buffer that contains the message to be signed.
    BinaryStringEncoding encoding = BinaryStringEncoding.Utf8;
    buffMsg = CryptographicBuffer.ConvertStringToBinary(strMsg, encoding);

    // Create a key to be signed with the message.
    IBuffer buffKeyMaterial = CryptographicBuffer.GenerateRandom(objMacProv.MacLength);
    hmacKey = objMacProv.CreateKey(buffKeyMaterial);

    // Sign the key and message together.
    buffHMAC = CryptographicEngine.Sign(hmacKey, buffMsg);

    // Verify that the HMAC length is correct for the selected algorithm
    if (buffHMAC.Length != objMacProv.MacLength)
    {
        throw new Exception("Error computing digest");
    }
 }


Requirements

Minimum supported client

Windows 8

Minimum supported server

Windows Server 2012

Minimum supported phone

Windows Phone 8.1 [Windows Runtime apps only]

Namespace

Windows.Security.Cryptography.Core
Windows::Security::Cryptography::Core [C++]

Metadata

Windows.winmd

See also

MacAlgorithmProvider

 

 

Show:
© 2014 Microsoft