Sun Java KeyManagerFactory 和空密码
Sun JRE 1.6 中的 KeyManagerFactory 存在问题。我们使用类似于以下的代码来上传和使用 p12 格式的证书:
KeyStore keyStore = KeyStore.getInstance(PKCS12);
KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(SUN_X509);
InputStream certificateFile = getSSLCertificate();
String certificatePassword = getSSLCertificatePassword();
keyStore.load(certificateFile, certificatePassword);
keyManagerFactory.init(keyStore, certificatePassword);
当证书密码存在时,此代码可以正常工作。但是,当证书密码为空(因此证书不受密码保护)时,我们会从 keyManagerFactory.init 行收到除零错误。
有谁知道为什么会发生这种情况?没有密码就不能使用证书吗? 谢谢
We are having a problem with the KeyManagerFactory in the Sun JRE 1.6. We are using code similar to the following to upload and use a certificate in p12 format:
KeyStore keyStore = KeyStore.getInstance(PKCS12);
KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(SUN_X509);
InputStream certificateFile = getSSLCertificate();
String certificatePassword = getSSLCertificatePassword();
keyStore.load(certificateFile, certificatePassword);
keyManagerFactory.init(keyStore, certificatePassword);
This code works correctly when the certificate password exists. But when the certificate password is null (so the certificate is not protected by a password) we get a divide by zero error from the keyManagerFactory.init line.
Does anyone know why this is happening? Is it not possible to use a certificate without a password?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是一个错误:
https://bugs.java.com/bugdatabase/view_bug?bug_id =6415637
解决方法是设置密码。
This is a bug:
https://bugs.java.com/bugdatabase/view_bug?bug_id=6415637
Workaround is to set a password.
由于 PKCS12 包含私钥,因此您应该始终拥有密码。我认为 Sun 无意中强制执行了这一点:)
对于所有 Keystore API,存储和私钥都需要密码。如果您真的不想处理配置或用户交互,只需在任何地方使用默认密码“changeit”即可。
Because PKCS12 contains private key, you should always have a password. I think Sun accidentally enforces this :)
For all Keystore API, password is required for the store and private keys. If you don't really want deal with the configuration or user-interaction, just use the default password "changeit" everywhere.
看来使用空字符数组将配置
KeyManagerFactory
以允许在没有密码的情况下访问密钥。有各种各样的原因需要使用没有密码的
KeyStore
(仅内存中的KeyStore是一种可能性)。It appears that using an empty character array will configure the
KeyManagerFactory
to allow access to the keys without a password.There are all kinds of reasons to have a
KeyStore
without a password (in-memory-only KeyStores being one possibility).