C++ 使用apachexmlsecurityc++;(XSec)

C++ 使用apachexmlsecurityc++;(XSec),c++,xml,cryptography,digital-signature,xml-signature,C++,Xml,Cryptography,Digital Signature,Xml Signature,使用ApacheXML安全库(xsec)3.1.1版实现封装和分离签名的正确方法是什么 我在寻找一些好的例子,但没有找到。 apache也列出了一个示例,但它仅用于创建封装签名。我发现解决方案非常简单 解析文档后,以下内容将生成信封签名(如指定): 以下内容将生成信封签名: XSECProvider prov; DSIGSignature * sig; DOMElement * sigNode; sig = prov.newSignature(); sigNode = sig-&g

使用ApacheXML安全库(xsec)3.1.1版实现封装和分离签名的正确方法是什么

我在寻找一些好的例子,但没有找到。
apache也列出了一个示例,但它仅用于创建封装签名。

我发现解决方案非常简单

解析文档后,以下内容将生成信封签名(如指定):

以下内容将生成信封签名:

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.
类似地,可以通过一些努力生成分离的签名

上面的例子涵盖了非常简单的情况。对多个数据项和文档子集进行签名需要付出一点努力

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.