2013-03-11 53 views

回答

0

我發現解決方案非常簡單。

一旦文檔已經被解析,以下將生成封裝簽名(如指定here):

// rootelem contains the root element of the parsed document 
XSECProvider prov; 
DSIGSignature * sig; 
DOMElement * sigNode; 

sig = prov.newSignature(); 
sigNode = sig->createBlankSignature(xercescdom, CANON_C14N_COM, SIGNATURE_HMAC, HASH_SHA1); 

// append the signature node to the document's element which is being signed, here 
// it is the root element 
rootelem->appendChild(xercescdom->createTextNode(MAKE_UNICODE_STRING("\n"))); 
rootelem->appendChild(sigNode); 
rootelem->appendChild(xercescdom->createTextNode(MAKE_UNICODE_STRING("\n"))); 

// create the envelope reference and the signing key (e.g. HMAC Key) 
// set the signing key 

sig->setSigningKey(hmackey); 

// other steps... Serializing the rootelem will generate an XML document with Enveloped Signature 

下面將生成一個包絡簽名:

XSECProvider prov; 
DSIGSignature * sig; 
DOMElement * sigNode; 

sig = prov.newSignature(); 
sigNode = sig->createBlankSignature(xercescdom, CANON_C14N_COM, SIGNATURE_HMAC, HASH_SHA1); 

// append an "Object" element to the signature object 
DSIGObject * object = sig->appendObject(); 
// in an enveloping signature, the "Object" element contains the data being signed 
// so the rootelem can be appended as a child to this object element 
object->appendChild(rootelem); 

// AND you are done! 
// now create the envelope reference and the signing key (e.g. HMAC Key) 
// set the signing key 

sig->setSigningKey(hmackey); 

// Serializing the signature node (sigNode) will give you the required XML with Enveloping Signature. 

類似地,分離的簽名可以通過一些努力來生成。

上面的例子涵蓋了非常簡單的情況。簽署多個數據項和文檔子集需要一點點努力。