Android and exception on introducing own custom key store

I'm generating a keystore from a certificate as follows:

export CLASSPATH=/Developer/BouncyCastle/bcprov-jdk16-146.jar
CERTSTORE=~/bitbucket/Android/CoooriJED/res/raw/mykeystore.bks
if [ -a $CERTSTORE ]; then
        rm $CERTSTORE || exit 1
fi
keytool \
        -importcert \
        -v \
        -trustcacerts \
        -alias 0 \
        -file <(openssl x509 -in mycert.pem) \
        -keystore $CERTSTORE \
        -storetype BKS \
        -provider org.bouncycastle.jce.provider.BouncyCastleProvider \
        -providerpath /Developer/BouncyCastle/bcprov-jdk16-146.jar \
        -storepass password

This generates a key store without apparent problem. In Eclipse I clean my Android project and see "mykeystore.bks" in the raw folder. I load the key store as follows:

private KeyStore keyStore()
{
    try {
        KeyStore trusted = KeyStore.getInstance("BKS");
        InputStream in = context.getResources().openRawResource(R.raw.mykeystore);
        try {
            trusted.load(in, "password".toCharArray()); // *Throws an exception*
        } finally {
        in.close();
        }
        return trusted;
    } catch (Exception e) {
        throw new AssertionError(e);
    }
}

I call this method as follows (I've removed the exception handling to make it easier to read here):

HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
KeyManagerFactory kmf = KeyManagerFactory.getInstance("X509");
kmf.init(keyStore(), "password".toCharArray());

However, the line trusted.load(in, "password".toCharArray()) is causing a "Wrong version of key store" IOException to be thrown. Why is that?

Thanking you in advance.

Answers


Could it be that you are using wrong version of bcprov jar? There are different versions of it and you need to choose the one that corresponds to your java sdk:

http://www.bouncycastle.org/latest_releases.html


Need Your Help

YouTubeThumbnailView in List View

android listview youtube thumbnails

I'm using the YouTube API to play videos from YouTube (obviously) which is working quite well so far. The issue I'm having is that I'm using a List View to display the different videos titles and

Any way to disable link functionality of #my_div without extracting it from "a"?

html hyperlink

Yes, this may seem a bit weird but I would like to disable the link functionality of #my_div without extracting it from a. Is there a way?