0
我需要签署一个XML文档。但是,要签名的XML元素没有ID。有没有办法通过标签名称添加签名?将签名添加到没有“ID”的XML元素
是这样的:
`<father>
<child>element to sign, without "id" </child>
<I need the signature here></I need the signature here>
</father>`
我明白我的问题是这样的句子:
Reference ref = fac.newReference("", fac.newDigestMethod(
DigestMethod.SHA1, null), Collections.singletonList(fac
.newTransform(Transform.ENVELOPED,
(TransformParameterSpec) null)), null, null);
我试着这样说:
Reference ref = fac.newReference("#child", fac.newDigestMethod(
DigestMethod.SHA1, null), Collections.singletonList(fac
.newTransform(Transform.ENVELOPED,
(TransformParameterSpec) null)), null, null);
但是,这将引发一个例外,因为它没有找到元素,第一个选项有效,但是签名被添加到xml文件的末尾:
`<father>
<child>element to sign, without "id" </child>
</father>
<Signature></Signature>`
任何推荐?
在此先感谢!
谢谢,这是工作,但我的老师说,我不能通过添加原始XML中不存在的属性来修改原始xml。我将寻找如何发送XML元素作为参考而不添加“id”属性 –
您确定您正在修改您的XML吗?我没有深入到fac.newReference(...),但它看起来像只使用#id连接来检索正确的标记... –