How to sign only specific part of XML

北战南征 提交于 2019-12-03 13:39:34

After much fighting with XML Signatures I finally arrived at an acceptable solution (though not ideal).

As it turns out an Exclusive canonicalization is not enough. You need to also add an Exclusive transform after all other transformers. Following the code snippets I wrote above:

List<Transform> transforms = new ArrayList<Transform>()
transforms.add(transform)
fac.newTransform(CanonicalizationMethod.EXCLUSIVE, (TransformParameterSpec) null)

This will make it so that any other namespaces outside of the signed elements will not be taken into account (though it has the added effect that inserting namespace(s) inside the signed element is allowed).

Also it seems that any element in the xpath to the signed element will be taken into account so if you have the following xpath /root/A/B it will sign tag B however you will not be able to change the tag name of either A or root elements.

This can be overcome by using an xpath with less elements in it such as //B.

I believe it may be possible to overcome this issue too though so far I have not been able to.

There are parameters, related to namespace, that can be passed to Exclusive XML Canonicalization that describe the InclusiveNamespaces PrefixList.

You could try passing a ExcC14NParameterSpec to newCanonicalizationMethod() using a prefix list to see if that affects the canonicalization of the namespaces.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!