我在SignedInfo中有这个
<ds:Reference URI="#Id-body">
<ds:transform>
...
...
整个XML文件就像这样
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header>
...
</soapenv:Header>
<soapenv:Body xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="Id-body">
<ns4:message>
...
...
</ns4:message>
</soapenv:Body>
</soapenv:Envelope>
我正在编写一个Java程序来计算数字签名的摘要值。我认为应该对以下内容进行哈希处理但是我收到错误说&#34;前缀&#34; soapenv&#34; for element&#34; soapenv:Body&#34;不受约束。&#34;所以我的问题是,应该使用哪些内容来获取摘要值?
<soapenv:Body xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="Id-body">
<ns4:message>
...
...
</ns4:message>
</soapenv:Body>
我的代码:
org.apache.xml.security.Init.init();
String test = "<soapenv:Body .....</sopaenv:Body>";
rawXmlBytes = test.getBytes();
Canonicalizer canon = Canonicalizer.getInstance(Canonicalizer.ALGO_ID_C14N_EXCL_WITH_COMMENTS);
byte[] canonXmlBytes = canon.canonicalize(rawXmlBytes);
MessageDigest md = MessageDigest.getInstance("SHA-1");
Base64 base64 = new Base64();
String digestValue = base64.encodeToString(md.digest(canonXmlBytes));