pfx证书导入 oracle,can't use a pfx file with no password in a KeyManagerFactory

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:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值