使用 WSSSignature API 的数字签名方法
可以使用 WSS API 为生成器绑定配置签名信息。要配置客户机以对请求签名,请选择数字签名方法。算法方法包括签名方法和规范方法。
必须配置生成器签名信息,以通过为 SOAP 消息进行数字签名来保护消息的完整性。完整性是指数字签名,而机密性是指加密。保证完整性可降低数据在网络中传输时被修改的风险。
在指定了要进行数字签名的消息部件之后,必须指定用来对消息进行数字签名的方法。
方法
可以使用下列方法来为信息签名:
- 签名方法
- 设置签名算法方法。
- 规范方法
- 设置规范算法方法。
签名算法
签名算法指定用来为证书签名的算法。签名算法指定签名方法的统一资源标识 (URI)。WebSphere® Application Server 支持以下预先配置的算法:
算法 | 描述 |
---|---|
WSSSignature.HMAC_SHA1 | 签名算法的 URI,HMAC:http://www.w3.org/2000/09/xmldsig#hmac-sha1 |
WSSSignature.RSA_SHA1(缺省值) | 签名算法的 URI,RSA:http://www.w3.org/2000/09/xmldsig#rsa-sha1 |
对于 WSS API,WebSphere Application Server 不支持 DSA-SHA1 算法 http://www.w3.org/2000/09/xmldsig#dsa-sha1
为请求生成者配置指定的签名算法必须与为请求使用者配置指定的算法相匹配。
规范算法
规范算法指定规范方法的统一资源标识 (URI)。WebSphere Application Server 支持以下预先配置的算法:
算法 | 描述 |
---|---|
WSSSignature.EXC_C14N(缺省值) | 排除规范算法的 URI,EXC_C14N:http://www.w3.org/2001/10/xml-exc-c14n# |
WSSSignature.C14N | 包含规范算法的 URI,C14N:http://www.w3.org/2001/10/xml-c14n# |
为请求生成者配置指定的规范算法必须与为请求使用者配置指定的算法相匹配。
以下示例提供了用于将 HMAC_SHA1 指定为签名方法和将 C14n 指定为规范方法的样本 WSS API 代码:
//generate WSSFactory instance
WSSFactory factory = WSSFactory.getInstance();
// generate WSSGenerationContext instance
WSSGenerationContext gencont = factory.newWSSGenerationContext();
// generate callback handler
X509GenerateCallbackHandler callbackHandler = new
X509GenerateCallbackHandler(
"",
"dsig-sender.ks",
"jks",
"client".toCharArray(),
"soaprequester",
"client".toCharArray(),
"CN=SOAPRequester, OU=TRL, O=IBM, ST=Kanagawa, C=JP",
null);
//generate the security token used to the signature
SecurityToken token = factory.newSecurityToken(X509Token.class,
callbackHandler);
//generate WSSSignature instance
WSSSignature sig = factory.newWSSSignature(token);
//set the canonicalization method
// DEFAULT: WSSSignature.EXC_C14N
sig.setCanonicalizationMethod(WSSSignature.C14N);
//set the signature method
// DEFAULT: WSSSignature.RSA_SHA1
sig.setSignatureMethod(WSSSignature.HMAC_SHA1);
//add the WSSSignature to the WSSGenerationContext
gencont.add(sig);
//generate the WS-Security header
gencont.process(msgcontext);