Код: Выделить всё
keytool -genkeypair -keyalg RSA -alias self_signed -keypass mypass -keystore mystore.jks -storepass mypass
Код: Выделить всё
// Initialise the HTTPS server
HttpsServer httpsServer = HttpsServer.create(address, 0);
SSLContext sslContext = SSLContext.getInstance("TLS");
// Initialise the keystore
String pw = "mypass";
char[] keyStorePassword = pw.toCharArray();
char[] keyPassword = pw.toCharArray();
KeyStore ks = KeyStore.getInstance("JKS");
File keyStoreFile = new File(Context.APP_STATE.getKeyStoreFile());
FileInputStream fis = new FileInputStream(keyStoreFile);
ks.load(fis, keyStorePassword);
// Set up the key manager factory
KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509");
kmf.init(ks, keyPassword);
// Set up the trust manager factory
TrustManagerFactory tmf = TrustManagerFactory.getInstance("SunX509");
tmf.init(ks);
// Set up the HTTPS context and parameters
sslContext.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
...
Подробнее здесь: [url]https://stackoverflow.com/questions/79115018/in-a-java-httpsserver-how-does-java-know-what-cert-to-pass-back-to-client[/url]