2014-02-11 83 views
3

我正嘗試將自簽名證書導入java控制面板中的可信證書。它位於安全選項卡 - >管理證書下。無論我在密鑰庫上設置的密碼多麼簡單,導入程序總是會告訴我我輸入的密碼無效。我也嘗試更改證書類型,但沒有運氣..我嘗試了所有這些。下面是我用來創建我的文件無法將證書導入到java控制面板中

keytool -genkey -keyalg RSA -keysize 2048 -keystore test_keystore.jks -alias test 

然後我生成我的CSR文件,Java控制面板作爲輸入

keytool -certreq -alias test -keystore test_keystore.jks -file test_certificate_request.csr 

由於這個簡單的步驟只是一個測試,密碼我我的設置非常簡單,所以它不是使用錯誤密碼或輸入錯誤的問題。然而,每次我導入我創建的test_certificate_request.csr文件時,它都會告訴我無效的密碼。

萬一它很重要,這裏是當我點擊「更多信息」按鈕時從導入程序生成的完整跟蹤軌跡。

java.io.IOException: toDerInputStream rejects tag type 45 
at sun.security.util.DerValue.toDerInputStream(Unknown Source) 
at sun.security.pkcs12.PKCS12KeyStore.engineLoad(Unknown Source) 
at java.security.KeyStore.load(Unknown Source) 
at com.sun.deploy.panel.CertificatesDialog.importPKCS12Certificate(Unknown Source) 
at com.sun.deploy.panel.CertificatesDialog.importButtonActionPerformed(Unknown Source) 
at com.sun.deploy.panel.CertificatesDialog.access$200(Unknown Source) 
at com.sun.deploy.panel.CertificatesDialog$4.actionPerformed(Unknown Source) 
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source) 
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source) 
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source) 
at javax.swing.DefaultButtonModel.setPressed(Unknown Source) 
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source) 
at java.awt.AWTEventMulticaster.mouseReleased(Unknown Source) 
at java.awt.Component.processMouseEvent(Unknown Source) 
at javax.swing.JComponent.processMouseEvent(Unknown Source) 
at java.awt.Component.processEvent(Unknown Source) 
at java.awt.Container.processEvent(Unknown Source) 
at java.awt.Component.dispatchEventImpl(Unknown Source) 
at java.awt.Container.dispatchEventImpl(Unknown Source) 
at java.awt.Component.dispatchEvent(Unknown Source) 
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source) 
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source) 
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source) 
at java.awt.Container.dispatchEventImpl(Unknown Source) 
at java.awt.Window.dispatchEventImpl(Unknown Source) 
at java.awt.Component.dispatchEvent(Unknown Source) 
at java.awt.EventQueue.dispatchEventImpl(Unknown Source) 
at java.awt.EventQueue.access$200(Unknown Source) 
at java.awt.EventQueue$3.run(Unknown Source) 
at java.awt.EventQueue$3.run(Unknown Source) 
at java.security.AccessController.doPrivileged(Native Method) 
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source) 
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source) 
at java.awt.EventQueue$4.run(Unknown Source) 
at java.awt.EventQueue$4.run(Unknown Source) 
at java.security.AccessController.doPrivileged(Native Method) 
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source) 
at java.awt.EventQueue.dispatchEvent(Unknown Source) 
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source) 
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source) 
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source) 
at java.awt.WaitDispatchSupport$2.run(Unknown Source) 
at java.awt.WaitDispatchSupport$4.run(Unknown Source) 
at java.security.AccessController.doPrivileged(Native Method) 
at java.awt.WaitDispatchSupport.enter(Unknown Source) 
at java.awt.Dialog.show(Unknown Source) 
at java.awt.Component.show(Unknown Source) 
at java.awt.Component.setVisible(Unknown Source) 
at java.awt.Window.setVisible(Unknown Source) 
at java.awt.Dialog.setVisible(Unknown Source) 
at com.sun.deploy.panel.SecurityPanel.certsBtnActionPerformed(Unknown Source) 
at com.sun.deploy.panel.SecurityPanel.access$300(Unknown Source) 
at com.sun.deploy.panel.SecurityPanel$4.actionPerformed(Unknown Source) 
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source) 
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source) 
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source) 
at javax.swing.DefaultButtonModel.setPressed(Unknown Source) 
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source) 
at java.awt.AWTEventMulticaster.mouseReleased(Unknown Source) 
at java.awt.Component.processMouseEvent(Unknown Source) 
at javax.swing.JComponent.processMouseEvent(Unknown Source) 
at java.awt.Component.processEvent(Unknown Source) 
at java.awt.Container.processEvent(Unknown Source) 
at java.awt.Component.dispatchEventImpl(Unknown Source) 
at java.awt.Container.dispatchEventImpl(Unknown Source) 
at java.awt.Component.dispatchEvent(Unknown Source) 
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source) 
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source) 
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source) 
at java.awt.Container.dispatchEventImpl(Unknown Source) 
at java.awt.Window.dispatchEventImpl(Unknown Source) 
at java.awt.Component.dispatchEvent(Unknown Source) 
at java.awt.EventQueue.dispatchEventImpl(Unknown Source) 
at java.awt.EventQueue.access$200(Unknown Source) 
at java.awt.EventQueue$3.run(Unknown Source) 
at java.awt.EventQueue$3.run(Unknown Source) 
at java.security.AccessController.doPrivileged(Native Method) 
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source) 
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source) 
at java.awt.EventQueue$4.run(Unknown Source) 
at java.awt.EventQueue$4.run(Unknown Source) 
at java.security.AccessController.doPrivileged(Native Method) 
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source) 
at java.awt.EventQueue.dispatchEvent(Unknown Source) 
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source) 
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source) 
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source) 
at java.awt.EventDispatchThread.pumpEvents(Unknown Source) 
at java.awt.EventDispatchThread.pumpEvents(Unknown Source) 
at java.awt.EventDispatchThread.run(Unknown Source) 

我在做什麼錯?

回答

5

keytool -certreq創建證書申請也被稱爲PKCS#10,應提供給證書頒發機構以獲得真實證書。然後將其上傳到期望證書的工具。

從堆棧跟蹤這些線路

at java.security.KeyStore.load(Unknown Source) 
at com.sun.deploy.panel.CertificatesDialog.importPKCS12Certificate(Unknown Source) 

我可以告訴大家,實際上UI預計在密鑰庫PKCS#12格式的證書裏,不只是一個單獨的證書。

這是如何生成的自簽名證書的密鑰庫與keytool

keytool -genkey -keyalg RSA -alias selfsigned -keystore keystore.jks \ 
    -storepass password -validity 360 -keysize 2048 

然而,在JKS格式這將創建密鑰庫和具有轉換爲PKCS#12格式的命令

keytool -importkeystore -srckeystore keystore.jks -srcstoretype JKS \ 
    -deststoretype PKCS12 -destkeystore keystore.p12 

或可替代地可以密鑰存儲在PKCS#12格式創建與指定-storetype

keytool -genkey -keyalg RSA -alias selfsigned -keystore keystore.p12 \ 
    -storetype pkcs12 -storepass password -validity 360 -keysize 2048 

請注意,密鑰庫包含自簽名證書以及相應的私鑰。

+0

謝謝工作完美。導入程序中的輸入文件將p12和csr文件列爲有效輸入,所以很奇怪只有p12文件可以工作。 –

+1

這實際上是一個非常好的問題,因爲通常證書具有.cer或.crt擴展名。 – divanov