code: public static RSAPublicKey getRSAPublicKeyFromPEM(Provider provider, String pem) {
          try {
              KeyFactory keyFactory = KeyFactory.getInstance("RSA", provider);
              return (RSAPublicKey) keyFactory.generatePublic(new X509EncodedKeySpec(getKeyBytesFromPEM(pem)));
          } catch (NoSuchAlgorithmException e) {
              throw new IllegalArgumentException("Algorithm SHA256withRSA is not available", e);
          } catch (InvalidKeySpecException e) {
              throw new IllegalArgumentException("Invalid PEM provided", e);
          }
      }
docs: Get an RSA public key utilizing the provided provider and PEM formatted string
  
  @param provider Provider to generate the key
  @param pem PEM formatted key string
  @return RSA public key