private void createKeystore() {
        if (aliasFile(KEY_STORE_FILE_EXTENSION).exists() &&
                aliasFile(KEY_PEM_FILE_EXTENSION).exists()) {
            return;
        }

        // Generate keystore in the async thread
        new Thread(new Runnable() {
            @Override
            public void run() {
                CertificateGenerator generator = new CertificateGenerator();
                KeyStore keystore;
                OutputStream os = null;
                Writer sw = null;
                JcaPEMWriter pw = null;
                try {
                    keystore = generator.generateRoot(JKS.this);
                    os = new FileOutputStream(aliasFile(KEY_STORE_FILE_EXTENSION));
                    keystore.store(os, password());

                    Certificate cert = keystore.getCertificate(alias());
                    sw = new FileWriter(aliasFile(KEY_PEM_FILE_EXTENSION));
                    pw = new JcaPEMWriter(sw);
                    pw.writeObject(cert);
                    pw.flush();
                    NetBareLog.i("Generate keystore succeed.");
                } catch (Exception e) {
                    NetBareLog.e(e.getMessage());
                } finally {
                    NetBareUtils.closeQuietly(os);
                    NetBareUtils.closeQuietly(sw);
                    NetBareUtils.closeQuietly(pw);
                }
            }
        }).start();
    }
A java keystore to manage root certificate.

@author Megatron King
@since 2018-11-10 20:06
netbare-core/src/main/java/com/github/megatronking/netbare/ssl/JKS.java