title: Android and exception on introducing own custom key store
body: <p>I'm generating a keystore from a certificate as follows:</p>
  
  <pre><code>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 &lt;(openssl x509 -in mycert.pem) \
          -keystore $CERTSTORE \
          -storetype BKS \
          -provider org.bouncycastle.jce.provider.BouncyCastleProvider \
          -providerpath /Developer/BouncyCastle/bcprov-jdk16-146.jar \
          -storepass password
  </code></pre>
  
  <p>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:</p>
  
  <pre><code>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);
      }
  }
  </code></pre>
  
  <p>I call this method as follows (I've removed the exception handling to make it easier to read here):</p>
  
  <pre><code>HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
  KeyManagerFactory kmf = KeyManagerFactory.getInstance("X509");
  kmf.init(keyStore(), "password".toCharArray());
  </code></pre>
  
  <p>However, the line <code>trusted.load(in, "password".toCharArray())</code> is causing a "Wrong version of key store" IOException to be thrown. Why is that?</p>
  
  <p>Thanking you in advance.</p>