Signs the document referenced in the <ds:Signature>
element that has been assigned to the signature property of this IXMDigitalSignature
object. The key object supplied must contain a private key and can be generated from one of the following methods:
createKeyFromCSP
createKeyFromCertContext
createKeyFromHMACSecret
createKeyFromHMACSecretBinary
createKeyFromNode
var oSignedKey = objXMLDigitalSignature.sign(oKey, fwWriteKeyInfo);
Set oSignedKey = objXMLDigitalSignature.sign(oKey, fwWriteKeyInfo)
IXMLDSigKeyPtr oSignedKey = objXMLDigitalSignature->sign(oKey, fwWriteKeyInfo);
HRESULT sign( IXMLDSigKey* oKey, XMLDSIG_WRITEKEYINFO fwWriteKeyInfo, IXMLDSigKey** oSignedKey);
IXMLDSigKey
interface. This object cannot be NULL.IXMLDSigKey
object used in signing. The return parameter is NULL if the method failed. Otherwise it is the same object passed in the oKey
parameter. In addition, the method passes the failure codes from CryptoAPI that are not covered by S_FALSE or NULL.
Signing using this method amounts to performing the following tasks:
<ds:Reference>
element under <ds:SignedInfo>
:
URI
attribute of the <ds:Reference>
element. If the URI
attribute is absent, data set by IXMLDigitalSignature::setReferenceData
is used.<ds:transforms>
child element.<ds:DigestMethod>
child element in the signature template and output the hash value as the text value of the <ds:DigestValue>
child element. <ds:SignatureMethod>
element with the name of the algorithm determined by the signing key. For HMAC, <ds:HMACOutputLength>
is created, if absent, and its content is set according to the value of the length
parameter of the createKeyFromHMACSecret
or createKeyFromHMACSecretBinary
method.<ds:SignedInfo>
element using the algorithm named in the <ds:CanonicalizationMethod>
element. <ds:SignedInfo>
to produce the signature hash.<ds:SignatureValue>
element.<ds:KeyInfo>
element according the value of fWriteKeyInfo
parameter passed to the sign
method.oSignedKey
parameter if signing succeeded. Otherwise return NULL.From this we see how a signature template might be set up. For more information on how to set up the signature template, see the discussions given in the signature Property
topic.
Note Thesign
method is the only method that can change the<ds:Signature>
element specified by thesignature
property.
Note You cannot sign any data in a non-trusted context, such as a script embedded in an HTML page. Doing so will result in an error.
The following example illustrates how the sign
method is used to sign data with XML digital signature. It uses a simple signature template (signature_template.sign.rsa.xml) as the input. The template has three empty sub elements: <ds:DigestValue>
, <ds:SignatureValue>
, and <ds:KeyInfo>
. The first two will be filled in after sign
returns. The last one will be filled in when sign
is called with fwWriteKeyInfo=KEYVALUE
. It is left intact if fwWriteKeyInfo=NOKEYINFO
and all the existing content is cleared if fwWriteKeyInfo=PURGE
. When fwWriteKeyInfo=CERTIFICATES
, a <X509Data>
element is inserted when the certificate of the key used is available.
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.