public static void main(String[] args)
            throws KeyStoreException, IOException, CertificateException, NoSuchAlgorithmException,
            NoSuchProviderException, UnrecoverableKeyException {
        HashMap<String, String> argsMap = new HashMap<>();
        for (int i = 0; i < args.length; i++) {
            String[] split = args[i].split("=");
            if (split.length > 1) {
                argsMap.put(split[0], split[1]);
            } else {
                argsMap.put(split[0], "");
            }
        }

        String keyPass = argsMap.get("keypass");
        String alias = argsMap.get("alias");
        String keystore = argsMap.get("keystore");

        KeyStore ks = KeyStore.getInstance("JKS", "SUN");
        try (final InputStream inputStream = Files.newInputStream(Paths.get(keystore))) {
            ks.load(inputStream, keyPass.toCharArray());
        }

        Key key = ks.getKey(alias, keyPass.toCharArray());

        if (key == null) {
            System.out.println("No key with alias " + alias);
            return;
        }

        System.out.println("-----BEGIN PRIVATE KEY-----");
        System.out.println(new String(Base64.encodeBase64(key.getEncoded())));
        System.out.println("-----END PRIVATE KEY-----");

        System.out.println("-----BEGIN CERTIFICATE-----");
        System.out.println(new String(Base64.encodeBase64(ks.getCertificate(alias).getEncoded())));
        System.out.println("-----END CERTIFICATE-----");
    }
Utility to export a private key and certificate from a key store.
<p>
E.g. java stroom.util.ExportKey
keystore=/home/user01/keys/server.keystore keypass=changeit alias=smrs
stroom-util/src/main/java/stroom/util/cert/ExportKey.java