5
我對Java SSL有困難。問題是我的鑰匙有密碼。當我使用命令openssl req -new -newkey rsa:1024 -nodes -out local.csr -keyout local.key
生成密鑰時,當詢問A challenge password []:
時,我輸入了MyKeyPass
。然後我從證書頒發機構獲得證書。然後我將證書導入到KeyStore和TrustStore中。如何使用javax.net.ssl指定密鑰密碼?
我的一個應用程序基於Jetty並使用Maven運行,另一個使用原始套接字,我沒有使用Maven。
當我用碼頭證書,使用下面的配置,一切正常:
<connector implementation="org.mortbay.jetty.security.SslSelectChannelConnector">
<port>443</port>
<maxIdleTime>30000</maxIdleTime>
<keystore>keys/domain.jks</keystore>
<password>KeyStorePass</password>
<keyPassword>MyKeyPass</keyPassword>
<truststore>keys/truststore_domain.jks</truststore>
<trustPassword>TrustStorePass</trustPassword>
</connector>
然而,對於應用程序不使用碼頭/ Maven的,下面的配置不工作:
-Djavax.net.ssl.keyStore=./keys/domain.jks \
-Djavax.net.ssl.keyStorePassword=KeyStorePass \
-Djavax.net.ssl.trustStore=./keys/truststore_domain.jks \
-Djavax.net.ssl.trustStorePassword=TrustStorePass \
我得到以下錯誤:
Caused by: java.security.UnrecoverableKeyException: Cannot recover key
at sun.security.provider.KeyProtector.recover(KeyProtector.java:328)
at sun.security.provider.JavaKeyStore.engineGetKey(JavaKeyStore.java:138)
at sun.security.provider.JavaKeyStore$JKS.engineGetKey(JavaKeyStore.java:55)
at java.security.KeyStore.getKey(KeyStore.java:792)
at sun.security.ssl.SunX509KeyManagerImpl.<init>(SunX509KeyManagerImpl.java:131)
at sun.security.ssl.KeyManagerFactoryImpl$SunX509.engineInit(KeyManagerFactoryImpl.java:68)
at javax.net.ssl.KeyManagerFactory.init(KeyManagerFactory.java:259)
at sun.security.ssl.SSLContextImpl$DefaultSSLContext.getDefaultKeyManager(SSLContextImpl.java:621)
at sun.security.ssl.SSLContextImpl$DefaultSSLContext.<init>(SSLContextImpl.java:486)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
at java.lang.Class.newInstance0(Class.java:372)
at java.lang.Class.newInstance(Class.java:325)
at java.security.Provider$Service.newInstance(Provider.java:1238)
... 12 more
。當然,這是缺少KeyPassword(MyKeyPass
)。我一直在試圖找到如何使用-Djavax.net.ssl
語法指定它,但似乎無法找到它。我如何指定密鑰密碼?
將'KeyStorePass'改爲'MyKeyPass'工作。謝謝。 – 2013-03-03 04:14:55