code: public static RSAPublicKey parseRSAPublicKey(String pem)
              throws CertificateException, UnsupportedEncodingException,
              ServletException {
          String PEM_HEADER = "-----BEGIN CERTIFICATE-----\n";
          String PEM_FOOTER = "\n-----END CERTIFICATE-----";
          String fullPem = PEM_HEADER + pem + PEM_FOOTER;
          PublicKey key = null;
          try {
              CertificateFactory fact = CertificateFactory.getInstance("X.509");
              ByteArrayInputStream is = new ByteArrayInputStream(fullPem.getBytes("UTF8"));
              X509Certificate cer = (X509Certificate) fact.generateCertificate(is);
              key = cer.getPublicKey();
          } catch (CertificateException ce) {
              String message = null;
              if (pem.startsWith(PEM_HEADER)) {
                  message = "CertificateException - be sure not to include PEM header " + "and footer in the PEM configuration element.";
              } else {
                  message = "CertificateException - PEM may be corrupt";
              }
              throw new ServletException(message, ce);
          } catch (UnsupportedEncodingException uee) {
              throw new ServletException(uee);
          }
          return (RSAPublicKey) key;
      }
docs: /*
  public static RSAPublicKey getPublicKeyFromFile(String filePath) throws
  IOException, CertificateException {
  FileUtils.readFileToString(new File(filePath));
  getPublicKeyFromString(pemString); }