@Test public void testCreatePkcs12() throws Exception { final String pkcsPath = "src/test/resources/internal.p12"; CertUtils.createPkcs12("src/test/resources/internal.key", "src/test/resources/internal.crt", pkcsPath); Path path = Paths.get(pkcsPath); assertTrue(Files.exists(path)); }
public static void createPkcs12(String filenameKey, String filenamePem, String filenameP12) throws Exception { Security.addProvider(new BouncyCastleProvider()); KeyPair keyPair = readKeyPairFromPemFile(filenameKey); PrivateKey privateKey = keyPair.getPrivate(); Certificate[] outChain = readCertificateChain(filenamePem); KeyStore outStore = KeyStore.getInstance("PKCS12"); outStore.load(null, InternalSSLKey.getKEY_PASSWORD()); outStore.setKeyEntry(InternalSSLKey.KEY_ALIAS, privateKey, InternalSSLKey.getKEY_PASSWORD(), outChain); try (OutputStream outputStream = new FileOutputStream(filenameP12)) { outStore.store(outputStream, InternalSSLKey.getKEY_PASSWORD()); outputStream.flush(); } }
CertUtils { public static void createPkcs12(String filenameKey, String filenamePem, String filenameP12) throws Exception { Security.addProvider(new BouncyCastleProvider()); KeyPair keyPair = readKeyPairFromPemFile(filenameKey); PrivateKey privateKey = keyPair.getPrivate(); Certificate[] outChain = readCertificateChain(filenamePem); KeyStore outStore = KeyStore.getInstance("PKCS12"); outStore.load(null, InternalSSLKey.getKEY_PASSWORD()); outStore.setKeyEntry(InternalSSLKey.KEY_ALIAS, privateKey, InternalSSLKey.getKEY_PASSWORD(), outChain); try (OutputStream outputStream = new FileOutputStream(filenameP12)) { outStore.store(outputStream, InternalSSLKey.getKEY_PASSWORD()); outputStream.flush(); } } }
CertUtils { public static void createPkcs12(String filenameKey, String filenamePem, String filenameP12) throws Exception { Security.addProvider(new BouncyCastleProvider()); KeyPair keyPair = readKeyPairFromPemFile(filenameKey); PrivateKey privateKey = keyPair.getPrivate(); Certificate[] outChain = readCertificateChain(filenamePem); KeyStore outStore = KeyStore.getInstance("PKCS12"); outStore.load(null, InternalSSLKey.getKEY_PASSWORD()); outStore.setKeyEntry(InternalSSLKey.KEY_ALIAS, privateKey, InternalSSLKey.getKEY_PASSWORD(), outChain); try (OutputStream outputStream = new FileOutputStream(filenameP12)) { outStore.store(outputStream, InternalSSLKey.getKEY_PASSWORD()); outputStream.flush(); } } private  CertUtils(); }
CertUtils { public static void createPkcs12(String filenameKey, String filenamePem, String filenameP12) throws Exception { Security.addProvider(new BouncyCastleProvider()); KeyPair keyPair = readKeyPairFromPemFile(filenameKey); PrivateKey privateKey = keyPair.getPrivate(); Certificate[] outChain = readCertificateChain(filenamePem); KeyStore outStore = KeyStore.getInstance("PKCS12"); outStore.load(null, InternalSSLKey.getKEY_PASSWORD()); outStore.setKeyEntry(InternalSSLKey.KEY_ALIAS, privateKey, InternalSSLKey.getKEY_PASSWORD(), outChain); try (OutputStream outputStream = new FileOutputStream(filenameP12)) { outStore.store(outputStream, InternalSSLKey.getKEY_PASSWORD()); outputStream.flush(); } } private  CertUtils(); static String getSubjectCommonName(X509Certificate cert); static String getSubjectSerialNumber(X509Certificate cert); static ClientId getSubjectClientId(X509Certificate cert); static boolean isAuthCert(X509Certificate cert); static boolean isSigningCert(X509Certificate cert); static boolean isValid(X509Certificate cert); static boolean isSelfSigned(X509Certificate cert); static String getOcspResponderUriFromCert(X509Certificate subject); static String[] getCertHashes(List<X509Certificate> certs); static String getRDNValue(X500Name name, ASN1ObjectIdentifier id); static byte[] generateCertRequest(PrivateKey privateKey, PublicKey publicKey, String
            principal); static KeyPair readKeyPairFromPemFile(String filename); static void writePemToFile(byte[] certBytes, String filename); static X509Certificate[] readCertificateChain(String filename); static void createPkcs12(String filenameKey, String filenamePem, String filenameP12); static String identify(X509Certificate certificate); }
CertUtils { public static void createPkcs12(String filenameKey, String filenamePem, String filenameP12) throws Exception { Security.addProvider(new BouncyCastleProvider()); KeyPair keyPair = readKeyPairFromPemFile(filenameKey); PrivateKey privateKey = keyPair.getPrivate(); Certificate[] outChain = readCertificateChain(filenamePem); KeyStore outStore = KeyStore.getInstance("PKCS12"); outStore.load(null, InternalSSLKey.getKEY_PASSWORD()); outStore.setKeyEntry(InternalSSLKey.KEY_ALIAS, privateKey, InternalSSLKey.getKEY_PASSWORD(), outChain); try (OutputStream outputStream = new FileOutputStream(filenameP12)) { outStore.store(outputStream, InternalSSLKey.getKEY_PASSWORD()); outputStream.flush(); } } private  CertUtils(); static String getSubjectCommonName(X509Certificate cert); static String getSubjectSerialNumber(X509Certificate cert); static ClientId getSubjectClientId(X509Certificate cert); static boolean isAuthCert(X509Certificate cert); static boolean isSigningCert(X509Certificate cert); static boolean isValid(X509Certificate cert); static boolean isSelfSigned(X509Certificate cert); static String getOcspResponderUriFromCert(X509Certificate subject); static String[] getCertHashes(List<X509Certificate> certs); static String getRDNValue(X500Name name, ASN1ObjectIdentifier id); static byte[] generateCertRequest(PrivateKey privateKey, PublicKey publicKey, String
            principal); static KeyPair readKeyPairFromPemFile(String filename); static void writePemToFile(byte[] certBytes, String filename); static X509Certificate[] readCertificateChain(String filename); static void createPkcs12(String filenameKey, String filenamePem, String filenameP12); static String identify(X509Certificate certificate);  }