使用 WSSSignPart API 的已签名的部件方法
可以使用 WSS API 为生成器绑定配置已签名的部件信息。算法包括摘要算法和变换方法。
可以通过配置已签名的部件信息和密钥信息来保护消息的完整性。完整性是指数字签名,而机密性是指加密。保证完整性可降低数据在网络中传输时被修改的风险。
方法
用于已签名的部件的方法包括:
- 摘要方法
- 设置摘要算法方法。
- 变换算法
- 设置变换算法方法。
摘要算法
在元素中将使用该元素中所指定的摘要方法算法。WebSphere® Application Server 支持以下预先配置的算法:
摘要方法 | 描述 |
---|---|
WSSSignPart.SHA1(缺省值) | 摘要算法的 URI,SHA1:http://www.w3.org/2000/09/xmldsig#sha1 |
WSSSignPart.SHA256 | 摘要算法的 URI,SHA256:http://www.w3.org/2001/04/xmlenc#sha256 |
WSSSignPart.SHA512 | 摘要算法的 URI,SHA256:http://www.w3.org/2001/04/xmlenc#sha512 |
变换算法
在元素中将使用该元素中所指定的变换方法算法。WebSphere Application Server 支持以下预先配置的算法:
摘要方法 | 描述 |
---|---|
WSSSignPart.TRANSFORM_ENVELOPED_SIGNATURE | 变换算法的 URI,被包络签名:http://www.w3.org/2000/09/xmldsig#enveloped-signature |
WSSSignPart.TRANSFORM_STRT10 | 变换算法的 URI,STR 变换:http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#STR-Transform |
WSSSignPart.TRANSFORM_EXC_C14N(缺省值) | 变换算法的 URI,Exc-C14N:http://www.w3.org/2001/10/xml-exc-c14n# |
WSSSignPart.TRANSFORM_XPATH2_FILTER | 变换算法的 URI,XPath2 过滤器:http://www.w3.org/2002/06/xmldsig-filter2 |
变换算法是在 <Transform> 元素中指定的,并指定已签名部件的变换算法。
对于 WSS API,WebSphere Application Server 不支持下列变换算法:
- http://www.w3.org/TR/1999/REC-xpath-19991116
- http://www.w3.org/2002/07/decrypt#XML
以下示例提供了用于指定签名和已签名部件、设置签名密钥和作为已签名部件来添加 STR-Transform 变换算法的样本 WSS API 代码:
// get the message context
Object msgcontext = getMessageContext();
//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 part specified by WSSSignPart
WSSSignPart sigPart = factory.newWSSSignPart();
//set the part specified by WSSSignPart
sigPart.setSignPart(WSSSignature.BODY);
//set the digest method specified by WSSSignPart
sigPart.setDigestMethod(WSSSignPart.SHA256);
//set the transform method specified by WSSSignPart
sigPart.addTransform(WSSSignPart.TRANSFORM_STRT10);
//set the part specified by WSSSignPart
sig.addSignPart(sigPart);
//add the WSSSignature to the WSSGenerationContext
gencont.add(sig);
//generate the WS-Security header
gencont.process(msgcontext);