title: BadPaddingException: Blocktype mismatch: 0
body: <p>So i have a android to PC communication ( android = client, PC = server )
  and when the client tries to connect to the server this is thrown at the server:</p>
  
  <pre><code>javax.crypto.BadPaddingException: Blocktype mismatch: 0
      at sun.security.rsa.RSAPadding.unpadV15(Unknown Source)
      at sun.security.rsa.RSAPadding.unpad(Unknown Source)
      at com.sun.crypto.provider.RSACipher.doFinal(RSACipher.java:356)
      at com.sun.crypto.provider.RSACipher.engineDoFinal(RSACipher.java:382)
      at javax.crypto.Cipher.doFinal(Cipher.java:2087)
  </code></pre>
  
  <p>but the same code for a pc client succesfully connects to the pc server ( PC &lt;-> PC Works, Android &lt;-> PC doesnt )</p>
  
  <p>Is there any difference in the android crypto that could cause this? I dont post any code since the code is huge and the 1:1 copy on the PC client works flawless.</p>
  
  <p>Server method to decrypt the packet:</p>
  
  <pre><code>public static Packet decompile(PacketWrapper wrapper, PrivateKey privateKey)
          throws Exception {
      for (Provider provider : Security.getProviders()) {
          System.out.println(provider.getName());
          System.out.println(provider.getInfo());
          System.out.println(System.lineSeparator());
      }
      Cipher cipher = Cipher.getInstance("RSA");
      cipher.init(Cipher.DECRYPT_MODE, privateKey);
      byte[] data = cipher.doFinal(wrapper.data);
      return (Packet) bytesToObj(data);
  }
  </code></pre>
  
  <p>Client method when sending the packet:</p>
  
  <pre><code>try {
      KeyGenerator kg = KeyGenerator.getInstance("AES");
      kg.init(AESsize, new SecureRandom());
      aesKey = (SecretKeySpec) kg.generateKey();
      new SecureRandom().nextBytes(ivKey);
  
      out.writeObject(Packet.compile(new ClientKeyPacket(aesKey, ivKey),
              publicKey));
  } catch (Exception e) {
      e.printStackTrace();
      print("Could not connect to the server");
      closeStreams("");
      return;
  }
  </code></pre>
  
  <p>where <code>Packet.compile()</code> is:</p>
  
  <pre><code>public static PacketWrapper compile(Packet packet, PublicKey publicKey)
          throws Exception {
      byte[] bytes = objToBytes(packet);
      System.out.println("Size &gt; " + bytes.length);
  
      Cipher cipher = Cipher.getInstance("RSA");
      cipher.init(Cipher.ENCRYPT_MODE, publicKey);
      byte[] data = cipher.doFinal(bytes);
      return new PacketWrapper(data);
  }    
  </code></pre>
  
  <p>and the <code>Crypt</code> static strings are:</p>
  
  <pre><code>public class Crypt {
      public static String saltMethod = "PBKDF2WithHmacSHA1";
      public static String encryptMethod = "AES/CBC/NoPadding";
      public static String shortEncrypt = "AES";
      public static String encoding = "UTF-8";
      public static int saltIterations = 5000;
      public static int saltLength = 8;
  }
  </code></pre>