KeyStore (@NotNull String path, @NotNull String password) { KeyStore keyStore; try { keyStore = KeyStore.getInstance(KeyStore.getDefaultType()); Path cacertsFile = Path.of(path); if (Files.exists(cacertsFile)) { try (InputStream stream = Files.newInputStream(cacertsFile)) { keyStore.load(stream, password.toCharArray()); } } else { try { Files.createDirectories(cacertsFile.getParent()); } catch (IOException e) { LOG.error("Cannot create directories: " + cacertsFile.getParent(), e); return null; } keyStore.load(null, password.toCharArray()); } } catch (Exception e) { LOG.error("Cannot create key store", e); return null; } return keyStore; }