This method generates a symmetric key based on a Base64-encoded value of an HMAC secret. The resultant key can be used in sign
and verify
.
var objKey = objXMLDigitalSignature.createKeyFromHMACSecret( secret, length );
Set objKey = objXMLDigitalSignature.createKeyFromHMACSecret( secret, _ length _ )
IXMLDSigKeyPtr objKey=objXMLDigitalSignature->createKeyFromHMACSecret( (BSTR)secret, (LONG)length );
HRESULT createKeyFromHMACSecret( BSTR secret, LONG length, IXMLDSigKey** objKey);
<ds:HMACOutputLength>
element in <ds:Signature>
. It can be a positive number in multiples of eight (8), but no greater than 128, or a negative one (-1). The positive value is used by sign
or verify
as the bit length of the secret. For -1, the default length defined in CryptoAPI or the content of <ds:HMACOutputLength>
element is used instead.
The actual length used in sign
or verify
depends on the combination of the value of the length
parameter and the content of <ds:HMACOutputLength>
element in the signature template or document. The following table shows the possible combinations, the length used to verify, and the values returned.
length value | <ds:HMACOutputLength> content | Actual length used in sign or verify | Return code from createKeyFromHAMCSecret | Return value from sign or verify |
---|---|---|---|---|
8*n, where n=1, 2, ..., 16 | Any value | The value of the length parameter |
S_OK | Regular return value |
-1 | 8*n, where n=1, 2, ..., 16 | The value of <ds:HMACOutputLength> |
S_OK | Regular return value |
-1 | Any value | The sign or verify method will fail. |
S_OK | E_FAIL |
-1 | Absent | CryptoAPI default length (128) |
S_OK | Regular return value |
Any value | Any value | No key will be created. The objKey parameter is returned as NULL. |
E_INVALIDARG | E_INVALIDARG |
IXMLDSigKey
interface. In Visual Basic, scripting languages, and C/C++ with smart pointers, this is the key object itself.The method returns the standard HRESULT values defined in CryptoAPI, including the following:
The HMAC secret value is shared by the signer and the signature verifier, and is not to be transmitted with the signature document.
The key generated by this method does not have any corresponding certificate. When this key is used in signing, the <ds:KeyInfo>
element and its children will be purged.
When the length
parameter value is -1, it is important that the <ds:HMACOutputLength>
element contains a positive number that is multiple of eight (8). An empty content or zero value would mean that the signature information will not be used.
This examples illustrates how to sign and verify a document using an HMAC secret value, "secret". The Base64 encoding of this value is "c2VjcmV0", and is used by the createKeyFromHMACSecret
method to generate a key for both signing and verifying a piece of data. The data for this example is the text string "Hello, World!".
We've provided source files for the sample in three languages: JScript, Visual Basic, and C++. The output is the same in each language.
IXMLDigitalSignature | IXMLDigitalSignatureEx
MSXML 5.0 and later
To view reference information for Visual Basic, C/C++, or Script only, click the Language Filter button in the upper-left corner of the page.
CreateKeyFromHMACSecretBinary Method