PemReader { public static List<X509Certificate> readCertificateChain(File certificateChainFile) throws IOException, GeneralSecurityException { String contents = new String(Files.readAllBytes(certificateChainFile.toPath()), US_ASCII); return readCertificateChain(contents); } private  PemReader(); static KeyStore loadTrustStore(File certificateChainFile); static KeyStore loadKeyStore(File certificateChainFile, File privateKeyFile, Optional<String> keyPassword); static List<X509Certificate> readCertificateChain(File certificateChainFile); static List<X509Certificate> readCertificateChain(String certificateChain); static PrivateKey loadPrivateKey(File privateKeyFile, Optional<String> keyPassword); static PrivateKey loadPrivateKey(String privateKey, Optional<String> keyPassword); static PublicKey loadPublicKey(File publicKeyFile); static PublicKey loadPublicKey(String publicKey);  }
@Test public void testLoadCertificateFromKeyStore() throws IOException, GeneralSecurityException { List<X509Certificate> certs = PemReader.readCertificateChain( x509TestContext.getKeyStoreFile(KeyStoreFileType.PEM)); Assert.assertEquals(1, certs.size()); Assert.assertEquals(x509TestContext.getKeyStoreCertificate(), certs.get(0)); }
@Test public void testLoadCertificateFromTrustStore() throws IOException, GeneralSecurityException { List<X509Certificate> certs = PemReader.readCertificateChain( x509TestContext.getTrustStoreFile(KeyStoreFileType.PEM)); Assert.assertEquals(1, certs.size()); Assert.assertEquals(x509TestContext.getTrustStoreCertificate(), certs.get(0)); }