title: Java/Android Bouncy castle ClassNotFoundException
body: <p>I am writing an application for the Android platform which makes use of cryptography. It's a secure chat, client->server->client with diffie hellman keys.
  Clients are android phones and the server is running on my PC.
  I am trying to send the public key via sockets but i am getting this error:</p>
  
  <pre><code>Server Up and Running
  Bouncy Castle provider is available
  Aug 21, 2016 4:47:03 PM Connection run
  SEVERE: null
  java.lang.ClassNotFoundException: com.android.org.bouncycastle.jcajce.provider.asymmetric.dh.BCDHPublicKey
  at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
  at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
  at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
  at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
  at java.lang.Class.forName0(Native Method)
  at java.lang.Class.forName(Class.java:348)
  at java.io.ObjectInputStream.resolveClass(ObjectInputStream.java:626)
  at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1613)
  at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1518)
  at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1774)
  at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1351)
  at java.io.ObjectInputStream.readObject(ObjectInputStream.java:371)
  at Connection.run(Connection.java:124)
  </code></pre>
  
  <p>As you can see bouncy castle provider is available.
  Here is my code with the problem:</p>
  
  <p>Server:</p>
  
  <pre><code>if (Security.getProvider("BC") == null){
        System.out.println("Bouncy Castle provider is NOT available");
  }
  else{
      System.out.println("Bouncy Castle provider is available");
      }
  
  try {
       pubkey = (PublicKey) instream.readObject();
  }catch (IOException ex) {}  
  </code></pre>
  
  <p>Android:</p>
  
  <pre><code>PublicKey pubkey;
  kp23 = genDHKeyPair();
  pubkey= kp23.getPublic();
  //System.out.println(pubkey);
  outstream.writeObject(pubkey);
  outstream.flush();
  </code></pre>