创建密钥对和数字证书:
签名和加密需要使用到数字证书和密钥对,可以使用JDK提供的KeyTool工具创建密钥对和数字证书。我们分别为服务端和客户端创建RSA密钥对,并生成各自的X509数字证书(包含公钥和数字签名)。服务端和客户端拥有各自的密钥库JKS文件,服务端的密钥库保存服务端的密钥对和客户端的数字证书,而客户端的密钥库保存客户端的密钥对和服务端的数字证书。
下面,我们来完成创建服务端和客户端密钥库的工作:
1、通过别名和密码创建私密钥到keystore:
keytool -genkey -alias ws_security -keypass keypassword -keystore privatestore.jks -storepass keyStorePassword -dname "cn=ws_security" -keyalg RSA
采用RSA算法进行处理。
2、证书:
keytool -selfcert -alias ws_security -keystore privatestore.jks -storepass keyStorePassword -keypass keypassword
3、导出公钥到key.rsa:
keytool -export -alias ws_security -file key.rsa -keystore privatestore.jks -storepass keyStorePassword
4、导入公钥到新的keystore中:
keytool -import -alias ws_security -file key.rsa -keystore publicstore.jks -storepass keyStorePassword
可以用一个批处理文件生成:
rem @echo off
echo alias fisher
echo keypass 123456
echo keystoreName server.jks
echo keystoreName2 client.jks
echo KeyStorePass 654321
echo keyName key.rsa
keytool -genkey -alias fisher -keypass 123456 -keystore server.jks -storepass 654321 -dname "cn=fisher" -keyalg RSA
keytool -selfcert -alias fisher -keystore server.jks -storepass 654321 -keypass 123456
keytool -export -alias fisher -file key.rsa -keystore server.jks -storepass 654321
keytool -import -alias fisher -file key.rsa -keystore client.jks -storepass 654321
|
properties文件的相关配置:
1、创建insecurity.properties:
org.apache.ws.security.crypto.provider=org.apache.ws.security.components.crypto.Merlin
org.apache.ws.security.crypto.merlin.keystore.type=jks
org.apache.ws.security.crypto.merlin.keystore.password=keyStorePassword
org.apache.ws.security.crypto.merlin.alias.password=keypassword
org.apache.ws.security.crypto.merlin.keystore.alias=ws_security
org.apache.ws.security.crypto.merlin.file=META-INF/xfire/publicstore.jks
2、创建outsecurity.properties:
org.apache.ws.security.crypto.provider=org.apache.ws.security.components.crypto.Merlin
org.apache.ws.security.crypto.merlin.keystore.type=jks
org.apache.ws.security.crypto.merlin.keystore.password=keyStorePassword
org.apache.ws.security.crypto.merlin.alias.password=keypassword
org.apache.ws.security.crypto.merlin.keystore.alias=ws_security
org.apache.ws.security.crypto.merlin.file=META-INF/xfire/privatestore.jks
3、把文件insecurity,outsecurity.properties,privatestore.jks和publicstore.jks复制到META-INF/xfire/下。
有关keytool的使用说明,请查看以下资料:
相关资料:#
阅读(1494) | 评论(0) | 转发(0) |