0

次のステートメントに従って、xades4j でエンベロープ署名を作成しています。

Element elemToSign = doc.getDocumentElement();
XadesSigner signer = new XadesTSigningProfile(...).newSigner();
new Enveloped(signer).sign(elemToSign);

しかし、署名には ProofOfApprova などの他のプロパティも含める必要があります...

xades4j の例では、さまざまな署名ステートメントを使用して、proofOfApprovalProperties がエンベロープ署名に追加されていることがわかります。次に例を示します。

AllDataObjsCommitmentTypeProperty globalCommitment = AllDataObjsCommitmentTypeProperty.proofOfApproval();
CommitmentTypeProperty commitment = CommitmentTypeProperty.proofOfCreation();

DataObjectDesc obj1 = new DataObjectReference('#' + elemToSign.getAttribute("Id"))
    .withTransform(new EnvelopedSignatureTransform())
    .withDataObjectFormat(new DataObjectFormatProperty("text/xml", "MyEncoding")
    .withDescription("Isto é uma descrição do elemento raiz")
    .withDocumentationUri("http://doc1.txt")
    .withDocumentationUri("http://doc2.txt"))
    .withIdentifier("http://elem.root"))
    .withCommitmentType(commitment)
    .withDataObjectTimeStamp(dataObjsTimeStamp)

SignedDataObjects dataObjs = new SignedDataObjects(obj1)
    .withCommitmentType(globalCommitment);

signer.sign(dataObjs, elemToSign);

ここでは、署名の別の手順が使用されていることがわかります。より具体的には、ルートタグに「Id」属性を使用するという DataObjectreference を作成するステートメントは、入力ではあらゆる種類の xml ドキュメントを持つことができ、できないため、使用できませんルートタグを定義するために使用できる属性の種類(存在する場合)を知っています。

簡単に言えば、Enveloped 署名を作成し、"new Enveloped(signer).sign(elemToSign);" を使用して、またはとにかく xml ソース構造を知らずに、proofOfApproval プロパティを配置するサンプル コードを用意できますか?

ありがとう

M.

4

1 に答える 1

1

署名されるデータ オブジェクトには、proofOfApproval プロパティを適用する必要があるため、SignedDataObjects クラスを使用する必要があります。

Enveloped クラスは、単純なシナリオの単なるヘルパーです。私の理解が正しければ、XML 文書全体に署名する必要があります。XML-Signatures 仕様では、参照の空の URI (URI="") がまさにそれを意味すると定義しています。Enveloped クラスのコードを確認すると、URI が空のDataObjectReferenceが追加されていることがわかります。

要約すると、次のようなものが必要になります。

DataObjectDesc obj1 = new DataObjectReference("")
    .withTransform(new EnvelopedSignatureTransform())
    .withCommitmentType(CommitmentTypeProperty.proofOfApproval());
signer.sign(new SignedDataObjects(obj1), elemToSign);
于 2012-08-24T14:12:51.513 に答える