Java Soap规范化变换
我正在尝试使用托管在Datapower设备上的soap服务。到目前为止,发送soap服务和接收方对以下xml的摘要计算方式不同 应用于创建摘要值的转换Java Soap规范化变换,java,xml,node.js,web-services,soap,Java,Xml,Node.js,Web Services,Soap,我正在尝试使用托管在Datapower设备上的soap服务。到目前为止,发送soap服务和接收方对以下xml的摘要计算方式不同 应用于创建摘要值的转换 <ds:Reference URI="#TS-f3c103e9-1897-43d8-8cf6-274bdb647678"> <ds:Transforms> <ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#">
<ds:Reference URI="#TS-f3c103e9-1897-43d8-8cf6-274bdb647678">
<ds:Transforms>
<ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#">
<ec:InclusiveNamespaces xmlns:ec="http://www.w3.org/2001/10/xml-exc-c14n#" PrefixList="wsse soap"/>
</ds:Transform>
</ds:Transforms>
<ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>
<ds:DigestValue>1rjXQQWVMM5KBWY8uswUynk6PCk=</ds:DigestValue>
</ds:Reference>
1RJXQWVMM5KBWY8USWUYNK6PCK=
引用的元素
<wsu:Timestamp wsu:Id="TS-f3c103e9-1897-43d8-8cf6-274bdb647678">
<wsu:Created>2016-02-24T15:32:12.693Z</wsu:Created>
<wsu:Expires>2016-02-24T15:37:12.693Z</wsu:Expires>
</wsu:Timestamp>
2016-02-24T15:32:12.693Z
2016-02-24T15:37:12.693Z
上述元素的名称空间应用于根节点
- xmlns:wsu=”http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
- xmlns:ds=”http://www.w3.org/2000/09/xmldsig#"
给定上述参考元素,在使用sha1散列之前,转换后的输出xml是什么?您需要弄清楚java库或API如何创建发送给sha1方法的规范化xml 使用apachecommons Codec()并从Timestamp元素和Transform元素中包含的名称空间中猜测C14N’d XML,我能够得到相同的摘要值:1rjXQQWVMM5KBWY8uswUynk6PCk= 以下是我使用的代码:
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.codec.digest.DigestUtils;
public class Sha1Test {
public static void main(String args[]) throws Exception {
String data = "<wsu:Timestamp xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:wsse=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd\" xmlns:wsu=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd\" wsu:Id=\"TS-f3c103e9-1897-43d8-8cf6-274bdb647678\"><wsu:Created>2016-02-24T15:32:12.693Z</wsu:Created><wsu:Expires>2016-02-24T15:37:12.693Z</wsu:Expires></wsu:Timestamp>";
printShaDigest(data);
}
static void printShaDigest(String data) {
System.out.println("data = " + data);
System.out.println("sha1 = " + new String(Base64.encodeBase64(DigestUtils.sha1(data.getBytes()))));
}
}
import org.apache.commons.codec.binary.Base64;
导入org.apache.commons.codec.digest.DigestUtils;
公共类Sha1Test{
公共静态void main(字符串args[])引发异常{
字符串数据=“2016-02-24T15:32:12.693Z2016-02-24T15:37:12.693Z”;
printShaDigest(数据);
}
静态void printShaDigest(字符串数据){
System.out.println(“数据=”+数据);
System.out.println(“sha1=“+新字符串(Base64.encodeBase64(DigestUtils.sha1(data.getBytes())))));
}
}