Does android support .jks keystore type?

Sankar picture Sankar · Feb 16, 2012 · Viewed 17.5k times · Source

I am trying to connect to server using keystore which is provided by server team.

While sending service call to server first i created KeyStore Instance by using following api

KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType());

It’s returning the keystore type as “BKS”.

The Keystore what server team sent is of type “.jks”(somename.jks) So, I am getting exception “Wrong version of key store”.

I tried by passing “JKS” to getInstance() of KeyStore by following way

KeyStore keystore = KeyStore.getInstance("JKS");       

But here I am getting exception “KeyStore JKS implementation not found”.

Here is the piece of code:

KeyStore trustStore  = KeyStore.getInstance(KeyStore.getDefaultType());

InputStream instream = mContext.getAssets().open("somename.jks");

try {
    trustStore.load(instream, "password".toCharArray());
} finally {
    try {
       instream.close();
    } catch(Exception ignore) {
    }
}

Please guide me to solve this problem.

Answer

Cehm picture Cehm · Feb 16, 2012

I think Android support 'only' BouncyCastle KeyStores (known as BKS)... You still can use Portecle

To convert it from JKS to BKS, should work like a charm (at least it worked for me when trying to store my .CRT into a BKS format ! ;)

'only' meaning, easily here :p, else you'll have to manipulate stuffs