I have a pfx file which contains a private key and a corresponding self-signed certificate. The pfx file itself is not protected by any password. I can't seem to use this pfx file to initialize a KeyManagerFactory for an SSL connection.
Here's some code which shows what I am trying to do:
InputStream ksStream = ResourceReader.getResourceAsStream("");
char[] password = null; //since the pfx file has no password on it
Keystore keyStore.load(ksStream, password);
KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509", "SunJSSE");
kmf.init(keystore, password);
This fails with this exception:
java.security.UnrecoverableKeyException: Get Key failed: / by zero
at com.sun.net.ssl.internal.pkcs12.PKCS12KeyStore.engineGetKey(PKCS12KeyStore.java:270)
at java.security.KeyStore.getKey(KeyStore.java:763)
at com.sun.net.ssl.internal.ssl.SunX509KeyManagerImpl.(SunX509KeyManagerImpl.java:113)
at com.sun.net.ssl.internal.ssl.KeyManagerFactoryImpl$SunX509.engineInit(KeyManagerFactoryImpl.java:48)
at javax.net.ssl.KeyManagerFactory.init(KeyManagerFactory.java:239)
at jsse.common.JsseSample.createKeyManagerFactory(JsseSample.java:294)
at jsse.common.JsseSample.createKeyManagerFactory(JsseSample.java:306)
at jsse.server.Simple.runSample(Simple.java:81)
at jsse.server.Simple.main(Simple.java:57)
Caused by: java.lang.ArithmeticException: / by zero
at com.sun.crypto.provider.PKCS12PBECipherCore.a(DashoA13*..)
at com.sun.crypto.provider.PKCS12PBECipherCore.a(DashoA13*..)
at com.sun.crypto.provider.PKCS12PBECipherCore.a(DashoA13*..)
at com.sun.crypto.provider.PKCS12PBECipherCore.a(DashoA13*..)
at com.sun.crypto.provider.PKCS12PBECipherCore$PBEWithSHA1AndDESede.engineInit(DashoA13*..)
at javax.crypto.Cipher.a(DashoA13*..)
at javax.crypto.Cipher.a(DashoA13*..)
at javax.crypto.Cipher.init(DashoA13*..)
at javax.crypto.Cipher.init(DashoA13*..)
at com.sun.net.ssl.internal.pkcs12.PKCS12KeyStore.engineGetKey(PKCS12KeyStore.java:251)
... 8 more
This code works fine if I put a password on the pfx file and then use that password to load the keystore and then use it in the KeyManagerFactory.
My question is: Why can I not use a pfx file that has not password on it?
Thanks,
R.
Edited by: 907570 on Jan 12, 2012 1:01 AM
Edited by: 907570 on Jan 12, 2012 1:18 AM
Tagged: