Skip to content

Instantly share code, notes, and snippets.

@gnh1201
Created July 30, 2019 06:33
Show Gist options
  • Select an option

  • Save gnh1201/841fc4368401da2ff5283324aa344ce6 to your computer and use it in GitHub Desktop.

Select an option

Save gnh1201/841fc4368401da2ff5283324aa344ce6 to your computer and use it in GitHub Desktop.
NanoHTTPD secure connection
KeyStore keystore = KeyStore.getInstance("JKS");
InputStream keystoreStream = new FileInputStream("keystore.jks");
if (keystoreStream == null) {
throw new IOException("Unable to load keystore from classpath: " + "keystore.jks");
}
keystore.load(keystoreStream, "password".toCharArray());
KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
keyManagerFactory.init(keystore, "password".toCharArray());
makeSecure(NanoHTTPD.makeSSLSocketFactory(keystore, keyManagerFactory), null);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment