Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
372 views
in Technique[技术] by (71.8m points)

bouncycastle - Android bouncy castle: IOException

I am using Sun's keytool to create a Bouncy castle keystore and import a certificate into it. The keytool does produce a keystore in the Bouncy castle format.

I then attempt to import the Bouncy castle keystore into an Android program. I am able to get an instance of the "BKS" keystore but calling load on the keystore throws

"java.io.IOException: Wrong version of key store".

This is the code

KeyStore keyStore = KeyStore.getInstance("BKS");
InputStream is = new FileInputStream("/mnt/sdcard/ArcGIS/mystore.bks");
keyStore.load(is, "abcdef".toCharArray());

I tried various versions of the Bouncy castle JAR downloaded from http://www.bouncycastle.org/latest_releases.html

What am I doing wrong?

Thanks, Ranjit

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

It seems the version of BouncyCastle shipped with Android 4.0.3 (API version 15) fails when trying to open keystores produced using the most recent BouncyCastle library. When I created a keystore using bcprov-jdk15on-147.jar, my sample Android app failed with the java.io.IOException: Wrong version of key store error.

However, if the keystore was created with the bcprov-jdk16-146.jar library, then it could be loaded by the application. My solution was to create the keystore with this older library.

Presumably this will also be the case for older API versions; try older versions of BouncyCastle when creating the keystore.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...