我使用xades4j库进行 xml 数字签名。签名似乎一切正常,但我意识到,如果 xml 文件具有非英文字母表中的特殊字母或重音符号,例如 é 或 ñ,则验证失败。我使用此代码进行数字签名和验证,这里是示例 xml,它在签名后无法验证:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<collection Id="root">
<album>
<title>Questions, unanswered</title>
<artist>Steve and the flubberblubs</artist>
<year>1989</year>
<t:tracks xmlns:t="http://test.xades4j/tracks">
<t:song tracknumber="1" length="4:05">
<t:title>What do you know?</t:title>
<t:artist>Steve é flubberblubs</t:artist>
<t:lastplayed>2006-10-17-08:31</t:lastplayed>
</t:song>
<t:song tracknumber="2" length="3:45">
<t:title>Who do you know?</t:title>
<t:artist>Steve and the flubberblubs</t:artist>
<t:lastplayed>2006-10-17-08:35</t:lastplayed>
</t:song>
<t:song tracknumber="3" length="5:14">
<t:title>When do you know?</t:title>
<t:artist>Steve and the flubberblubs</t:artist>
<t:lastplayed>2006-10-17-08:39</t:lastplayed>
</t:song>
<t:song tracknumber="4" length="4:19">
<t:title>Do you know?</t:title>
<t:artist>Steve and the flubberblubs</t:artist>
<t:lastplayed>2006-10-17-08:44</t:lastplayed>
</t:song>
</t:tracks>
</album>
</collection>
我得到的例外是:
[main] WARN org.apache.xml.security.signature.Reference - Verification failed for URI "#root"
[main] WARN org.apache.xml.security.signature.Reference - Expected Digest: KHQDbFVesKu/iTx7o1ad80ADwyDo1/sw/bagFpPMNH0=
[main] WARN org.apache.xml.security.signature.Reference - Actual Digest: S+7XIBhTeXQZ8UOdz1e2gbM1mJFrN9c/pEForMZw0p4=
[main] WARN org.apache.xml.security.signature.Reference - Verification failed for URI "#root"
[main] WARN org.apache.xml.security.signature.Reference - Expected Digest: KHQDbFVesKu/iTx7o1ad80ADwyDo1/sw/bagFpPMNH0=
[main] WARN org.apache.xml.security.signature.Reference - Actual Digest: S+7XIBhTeXQZ8UOdz1e2gbM1mJFrN9c/pEForMZw0p4=
[main] WARN org.apache.xml.security.signature.Reference - Verification failed for URI "#root"
[main] WARN org.apache.xml.security.signature.Reference - Expected Digest: KHQDbFVesKu/iTx7o1ad80ADwyDo1/sw/bagFpPMNH0=
[main] WARN org.apache.xml.security.signature.Reference - Actual Digest: S+7XIBhTeXQZ8UOdz1e2gbM1mJFrN9c/pEForMZw0p4=
Exception in thread "main" xades4j.verification.ReferenceValueException: Reference '#root' cannot be validated
at xades4j.verification.XadesVerifierImpl.doCoreVerification(XadesVerifierImpl.java:313)
at xades4j.verification.XadesVerifierImpl.verify(XadesVerifierImpl.java:195)
at xadesTest.Test2.verifyBes(Test2.java:184)
at xadesTest.Test2.main(Test2.java:84)
如果从 xml 中删除变音符号,则验证成功。我不知道代码是否缺少任何东西或其他地方有问题。先感谢您。