1

Apache XML セキュリティ ライブラリ (xsec) バージョン 3.1.1 を使用してエンベロープ署名と分離署名を実装する正しい方法は何ですか?

良い例を探しましたが、見つかりませんでした。apache のWeb サイトにも例がリストされていますが、これは Enveloped Signatures のみを作成するためのものです。

4

1 に答える 1

0

解決策は非常に簡単であることがわかりました。

ドキュメントが解析されると、次のようにエンベロープ署名が生成されます (ここで指定)。

// 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.

同様に、分離された署名は、多少の努力で生成できます。

上記の例は、非常に単純なケースをカバーしています。複数のデータ項目とドキュメントのサブセットに署名するには、少し手間がかかります。

于 2013-03-13T07:02:49.620 に答える