public static RSAPrivateKey getRSAPrivateKeyFromPEM ( Provider provider , String pem ) { try { KeyFactory keyFactory = KeyFactory . getInstance ( "RSA" , provider ) ; return ( RSAPrivateKey ) keyFactory . generatePrivate ( new PKCS8EncodedKeySpec ( getKeyBytesFromPEM ( pem ) ) ) ; } catch ( NoSuchAlgorithmException e ) { throw new IllegalArgumentException ( "Algorithm SHA256withRSA is not available" , e ) ; } catch ( InvalidKeySpecException e ) { throw new IllegalArgumentException ( "Invalid PEM provided" , e ) ; } }
Get an RSA private key utilizing the provided provider and PEM formatted string