title: Problem creating RSA public key from text in Bouncy Castle
body: <p>I have a problem to create a public key from a public key text. I found the solution from this link <a href="https://stackoverflow.com/questions/33425446/creating-rsa-public-key-from-string/33426378#">Creating RSA Public Key From String</a>. They mentioned Bouncy Castle (lightweight API) as a library to solve the <strong>InvalidKeySpecException</strong> error when converting a public key string to a RSA public key. But this solution failed with my case. The program throws an exception here </p>
  
  <p><strong>Exception in thread "main" java.lang.IllegalArgumentException: Bad sequence size: 9</strong></p>
  
  <p><a href="https://stackoverflow.com/questions/33425446/creating-rsa-public-key-from-string/33426378#">Creating RSA Public Key From String</a></p>
  
  <pre><code>   String publicKeyB64 = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA3AQKDhhtcM5A1a8R9/VX" +
              "mrocKGaQlat2/MRFy/Y1fTabYyKkfgaRXyrHiRn+imq3ljEgx/vLRTTPtLt8H79a" +
              "iMU6WJkQwG504NCnDRVB9DZBoAYDtBkjtje7I2Xs3tzvlNwM0bcCmmj/6QE9rHEv" +
              "xhvvXO8M332hINORLNiCF6NvYHrIVSa8EU4F0bnlWpoNi0YhP45uyOOuPpVmsaxp" +
              "MWOycf3nTICKK5BDylnVO7kMcL1utJxOOb1fsotaLuge4fF84DG4cPpLZko3ksB/" +
              "voOLTDv5QRsn++8qRciK4sptlnOs8g2TrXjE/rZlP9QmpUV4a3iQ1WmsqWQVizmw" +
              "PwIDAQAB";
  
      byte[] decoded = Base64.getDecoder().decode(publicKeyB64);
      org.bouncycastle.asn1.pkcs.RSAPublicKey pkcs1PublicKey = org.bouncycastle.asn1.pkcs.RSAPublicKey.getInstance(decoded);
      BigInteger modulus = pkcs1PublicKey.getModulus();
      BigInteger publicExponent = pkcs1PublicKey.getPublicExponent();
      RSAPublicKeySpec keySpec = new RSAPublicKeySpec(modulus, publicExponent);
      KeyFactory kf = KeyFactory.getInstance("RSA");
      PublicKey generatedPublic = kf.generatePublic(keySpec);
      System.out.printf("Modulus: %X%n", modulus);
      System.out.printf("Public exponent: %d ... 17? Why?%n", publicExponent); // 17? OK.
      System.out.printf("See, Java class result: %s, is RSAPublicKey: %b%n", generatedPublic.getClass().getName(), generatedPublic instanceof RSAPublicKey);
  </code></pre>
  
  <p>So I'm really expecting advice to handle this.</p>