转载:http://blog.csdn.net/qingkangxu/article/details/6095139
java.security.UnrecoverableKeyException: Cannot recover
分类: java基础
2010-12-23 21:10
272人阅读
评论(0)
收藏
举报
写一个基于SSL的Socket Server端程序,代码很简单
- SSLServerSocketFactory ssf = (SSLServerSocketFactory) SSLServerSocketFactory.getDefault();
- for(String cipher:ssf.getDefaultCipherSuites()){
- System.out.println("DefaultCipherSuite:" + cipher);
- }
- for(String cipher:ssf.getSupportedCipherSuites()){
- System.out.println("SupportedCipherSuite:" + cipher);
- }
- SSLServerSocket ss = (SSLServerSocket)ssf.createServerSocket(9999);
- System.out.println("Waiting for connection...");
- while (true) {
- Socket s = ss.accept();
- PrintStream out = new PrintStream(s.getOutputStream());
- out.println("Hi");
- out.close();
- s.close();
- }
2,java -Djavax.net.ssl.keyStore=server.jks -Djavax.net.ssl.keyStorePassword=123456 -Djavax.net.debug=all security.ssl.MySSLServer
居然出现default context init failed: java.security.UnrecoverableKeyException: Cannot recover
原来居然是:生成keystore的时候,别名密码和keystore的密码必须一致。比如如下:
keytool -genkey -keystore server.jks -storePass 123456 -alias server -keypass 123456
真是汗了,那keystore里面有多个别名怎么办,都要和keystore的密码一样,不知道jdk怎么想的,需要验证一下。