Pems { public static KeySpec privateKeySpec(InputSupplier<? extends InputStream> supplier) throws IOException { return fromPem( supplier, new PemProcessor<KeySpec>(ImmutableMap.<String, PemProcessor.ResultParser<KeySpec>> of( PRIVATE_PKCS1_MARKER, DecodeRSAPrivateCrtKeySpec.INSTANCE, PRIVATE_PKCS8_MARKER, new PemProcessor.ResultParser<KeySpec>() { @Override public KeySpec parseResult(byte[] bytes) throws IOException { return new PKCS8EncodedKeySpec(bytes); } }))); }  static T fromPem(InputSupplier<? extends InputStream> supplier, PemProcessor<T> processor); static KeySpec privateKeySpec(InputSupplier<? extends InputStream> supplier); static KeySpec privateKeySpec(String pem); static KeySpec publicKeySpec(InputSupplier<? extends InputStream> supplier); static KeySpec publicKeySpec(String pem); static X509Certificate x509Certificate(InputSupplier<? extends InputStream> supplier,
         @Nullable CertificateFactory certFactory); static X509Certificate x509Certificate(String pem); static String pem(X509Certificate cert); static String pem(PublicKey key); static String pem(PrivateKey key); static final String PRIVATE_PKCS1_MARKER; static final String PRIVATE_PKCS8_MARKER; static final String CERTIFICATE_X509_MARKER; static final String PUBLIC_X509_MARKER; static final String PUBLIC_PKCS1_MARKER; }
@Test(expectedExceptions = IllegalStateException.class, expectedExceptionsMessageRegExp = "^Invalid PEM: no parsers for marker -----BEGIN FOO PRIVATE KEY----- .*") public void testPrivateKeySpecFromPemWithInvalidMarker() throws IOException { Pems.privateKeySpec(Payloads.newStringPayload(INVALID_PRIVATE_KEY)); }
@Test public void testPrivateKeySpecFromPem() throws IOException { Pems.privateKeySpec(Payloads.newStringPayload(PRIVATE_KEY)); }