Wrong version of keystore on android call

I want to make a https request.

I use bouncycastle to generate the keystore like this :

keytool -importcert -trustcacerts -alias ludevCA -file lu_dev_cert.crt -keypass mypass -keystore keystore.bks -storepass mypass -storetype BKS -providerclass org.bouncycastle.jce.provider.BouncyCastleProvider -providerpath bcprov-jdk15on-146.jar  

And the keylist command return a correct value.

But when i do :

KeyStore ks = KeyStore.getInstance("BKS");
InputStream in = getResources().openRawResource(R.raw.keystore);  
ks.load(in, "mypass".toCharArray());

i have a error :

wrong version of keystore

I tried to use several version of bouncycast, but the result is the same. I also tried to define keysize 1024, but nothing change.

Any ideas ?


Have a Look on it Android: Trusting SSL certificates

  -storetype BKS
  -provider org.bouncycastle.jce.provider.BouncyCastleProvider
  -providerpath /path/to/bouncycastle.jar

And use this version when creating your keystore: Version 1.46 found here

May it Helps...


You need to change the type of the keystore, from BKS to BKS-v1 (BKS-v1 is an older version of BKS). Because the BKS version changed as said here

There is another solution, that is much much easier:

  1. Using Portecle:
  • Downloads Portecle http://portecle.sourceforge.net/
  • Open your bks file with the password and portecle
  • Do Tools>>Change Keystore Type>>BKS-v1
  • Save the file
  1. You may use KeyStore Explorer

The new file will be encoded with BKS-v1 and will not show the error anymore. To change the KeyStore type, open KeyStore Explorer and go to Tools -> Change KeyStore Type and then save the file.

Note:
Android works with different BKS versions: for instance, API 15 will require BKS-1 contrary to API 23 which requires BKS, so you may need to put both files in your app.

You can use this code to switch between them depending on the API level:

int bks_version;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
    bks_version = R.raw.publickey; //The BKS file
} else {
    bks_version = R.raw.publickey_v1; //The BKS (v-1) file
}
KeyStore ks = KeyStore.getInstance("BKS");
InputStream in = getResources().openRawResource(bks_version);  
ks.load(in, "mypass".toCharArray());

Finally i used a graphic editor (KeyStore Explorer) under Windows and it's working.

Maybe the error was caused by Java/Mac version problems