NanoHttpd / nanohttpd

Tiny, easily embeddable HTTP server in Java.
http://nanohttpd.org
BSD 3-Clause "New" or "Revised" License
6.92k stars 1.69k forks source link

java.io.IOException: Wrong version of key store. #523

Open GMF018 opened 5 years ago

GMF018 commented 5 years ago

When I try to set Https for it .

LordFokas commented 5 years ago

You need to be more specific. If you want help, you must provide as much detail on what you're doing and what's happening if you want someone to help you figure out what is the problem and why.

vitiruiz commented 5 years ago

I am also facing this issue.

I have crated a self signed certificate with keytool:

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

And when I try the following code, it thorws an IOException: Wrong version of key store.

KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType());
InputStream keystoreStream = MainActivity.getContext().getAssets().open("keystore.jks");
keystore.load(keystoreStream, "password".toCharArray());
GMF018 commented 5 years ago

Files generated from documents to support https, and log error Wrong version of key store.

InputStream keystoreStream = mContext.getAssets().open("test");
                KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType());
                keystore.load(keystoreStream, "123456".toCharArray());
                KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
                keyManagerFactory.init(keystore, "123456".toCharArray());

                localserver.setServerSocketFactory(new NanoHTTPD.SecureServerSocketFactory(
                        NanoHTTPD.makeSSLSocketFactory(keystore, keyManagerFactory), null));
                keystoreStream.close();
                localserver.start();

this is my code .

GMF018 commented 5 years ago

You need to be more specific. If you want help, you must provide as much detail on what you're doing and what's happening if you want someone to help you figure out what is the problem and why.

I am also facing this issue.

I have crated a self signed certificate with keytool:

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

And when I try the following code, it thorws an IOException: Wrong version of key store.

KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType());
InputStream keystoreStream = MainActivity.getContext().getAssets().open("keystore.jks");
keystore.load(keystoreStream, "password".toCharArray());

Have you solve this problem?

ravibpatel commented 4 years ago

It only supports the BKS-V1 Keystore. You can use a tool like KeyStore Explorer to change the type of KeyStore to BKS-V1.

https://stackoverflow.com/a/51763282/1273550