Wrong version of keystore on android call

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());

Leave a Comment