@SuppressWarnings("static-method") @Test @Ignore public void testSslpkcs12Generation() throws Exception { final CertPack certPack = CertUtil.getCertPackForHostSsl( "tomcat", "12341234", "127.0.0.1", new String[] { "demo.tgm" }, "cn=ca-clavefirma" ); final byte[] p12Bytes = certPack.getPkcs12(); try ( final OutputStream fos = new FileOutputStream( File.createTempFile("PKCS12_SSL_", ".P12") ); ) { fos.write(p12Bytes); fos.flush(); } final byte[] caCert = certPack.getCaCertificate().getEncoded(); try ( final OutputStream fos = new FileOutputStream( File.createTempFile("CA_SSL_", ".cer") ); ) { fos.write(caCert); fos.flush(); } }
static CertPack getCertPackForHostSsl(final String sslCertificateAlias, final String storePassword, final String ipAddress, final String[] hostNames, final String rootName) throws NoSuchAlgorithmException, CertificateException, IOException { Security.addProvider(new BouncyCastleProvider()); final PrivateKeyEntry caCertificatePrivateKeyEntry = generateCaCertificate( rootName ); final PrivateKeyEntry sslCertificatePrivateKeyEntry = generateSslCertificate( ipAddress, hostNames, caCertificatePrivateKeyEntry ); return new CertPack( caCertificatePrivateKeyEntry.getCertificate(), sslCertificatePrivateKeyEntry, sslCertificateAlias, storePassword.toCharArray() ); }
CertUtil { static CertPack getCertPackForHostSsl(final String sslCertificateAlias, final String storePassword, final String ipAddress, final String[] hostNames, final String rootName) throws NoSuchAlgorithmException, CertificateException, IOException { Security.addProvider(new BouncyCastleProvider()); final PrivateKeyEntry caCertificatePrivateKeyEntry = generateCaCertificate( rootName ); final PrivateKeyEntry sslCertificatePrivateKeyEntry = generateSslCertificate( ipAddress, hostNames, caCertificatePrivateKeyEntry ); return new CertPack( caCertificatePrivateKeyEntry.getCertificate(), sslCertificatePrivateKeyEntry, sslCertificateAlias, storePassword.toCharArray() ); } }
CertUtil { static CertPack getCertPackForHostSsl(final String sslCertificateAlias, final String storePassword, final String ipAddress, final String[] hostNames, final String rootName) throws NoSuchAlgorithmException, CertificateException, IOException { Security.addProvider(new BouncyCastleProvider()); final PrivateKeyEntry caCertificatePrivateKeyEntry = generateCaCertificate( rootName ); final PrivateKeyEntry sslCertificatePrivateKeyEntry = generateSslCertificate( ipAddress, hostNames, caCertificatePrivateKeyEntry ); return new CertPack( caCertificatePrivateKeyEntry.getCertificate(), sslCertificatePrivateKeyEntry, sslCertificateAlias, storePassword.toCharArray() ); }  }
CertUtil { static CertPack getCertPackForHostSsl(final String sslCertificateAlias, final String storePassword, final String ipAddress, final String[] hostNames, final String rootName) throws NoSuchAlgorithmException, CertificateException, IOException { Security.addProvider(new BouncyCastleProvider()); final PrivateKeyEntry caCertificatePrivateKeyEntry = generateCaCertificate( rootName ); final PrivateKeyEntry sslCertificatePrivateKeyEntry = generateSslCertificate( ipAddress, hostNames, caCertificatePrivateKeyEntry ); return new CertPack( caCertificatePrivateKeyEntry.getCertificate(), sslCertificatePrivateKeyEntry, sslCertificateAlias, storePassword.toCharArray() ); }   }
CertUtil { static CertPack getCertPackForHostSsl(final String sslCertificateAlias, final String storePassword, final String ipAddress, final String[] hostNames, final String rootName) throws NoSuchAlgorithmException, CertificateException, IOException { Security.addProvider(new BouncyCastleProvider()); final PrivateKeyEntry caCertificatePrivateKeyEntry = generateCaCertificate( rootName ); final PrivateKeyEntry sslCertificatePrivateKeyEntry = generateSslCertificate( ipAddress, hostNames, caCertificatePrivateKeyEntry ); return new CertPack( caCertificatePrivateKeyEntry.getCertificate(), sslCertificatePrivateKeyEntry, sslCertificateAlias, storePassword.toCharArray() ); }    }