HTTPS Server on Android Device Using NanoHttpd

前端 未结 4 721
忘掉有多难
忘掉有多难 2021-02-01 11:04

I am trying to run an HTTPS Server on an Android device using NanoHttpd (my final goal is to run WSS server on Android). I successfully ran HTTP Server and Websocket using NanoH

4条回答
  •  被撕碎了的回忆
    2021-02-01 11:41

    This link has solution: https://www.baeldung.com/nanohttpd#https

    use keytool generate jks

    keytool -genkey -keyalg RSA -alias selfsigned
      -keystore keystore.jks -storepass your_password -validity 360
      -keysize 2048 -ext SAN=DNS:localhost,IP:127.0.0.1  -validity 9999
    

    move keystore.jks to project src/main/resources

    and use following code:

    public class HttpsExample  extends NanoHTTPD {
     
        public HttpsExample() throws IOException {
            super(8080);
            makeSecure(NanoHTTPD.makeSSLSocketFactory(
              "/keystore.jks", "password".toCharArray()), null);
            start(NanoHTTPD.SOCKET_READ_TIMEOUT, false);
        }
     
        // main and serve methods
    }
    

提交回复
热议问题