天天看点

WS-Security: axis, cxf使用wss4j的中文处理问题

就我碰到的,中文问题主要是2个:

1) 传出的字符乱码

2) 出现如下异常:

[quote]org.apache.ws.security.WSSecurityException: The signature or decryption was invalid; nested exception is:

org.apache.xml.security.encryption.XMLEncryptionException: [color=red]An invalid XML character (Unicode: 0x10) was found in the element content of the document.[/color]

Original Exception was org.xml.sax.SAXParseException: An invalid XML character (Unicode: 0x10) was found in the element content of the document.

at org.apache.ws.security.processor.EncryptedKeyProcessor.decryptDataRef(EncryptedKeyProcessor.java:431)

at org.apache.ws.security.processor.EncryptedKeyProcessor.handleEncryptedKey(EncryptedKeyProcessor.java:342)

at org.apache.ws.security.processor.EncryptedKeyProcessor.handleEncryptedKey(EncryptedKeyProcessor.java:92)

at org.apache.ws.security.processor.EncryptedKeyProcessor.handleToken(EncryptedKeyProcessor.java:80)

at org.apache.ws.security.WSSecurityEngine.processSecurityHeader(WSSecurityEngine.java:311)[/quote]

升级wss4j到1.5.5可解决问题,主要有2个jar包需要替换:以1.5.4到1.5.5为例

1) wss4j-1.5.4.jar -> wss4j-1.5.5.jar

2) xmlsec-1.4.0.jar -> xmlsec-1.4.2.jar

中文处理问题可能与xmlsec-1.4.0的一个问题有关:

[quote]Xml canonization - UTF-8 encoding issue in Xml security 1.4.0.

Committed by RB. Thanks to Karol Rewera. See Issue [url=http://issues.apache.org/bugzilla/show_bug.cgi?id=41462]41462[/url][/quote]

该问题在xmlsec-1.4.1中解决。

Apache XML Security History of Changes:

[url=http://santuario.apache.org/changes.html]http://santuario.apache.org/changes.html[/url]