1

我正在使用 jks 文件注册密钥库,但得到“密钥库的错误版本”。使用以下代码

TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
        KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());

        InputStream keyStoreStream=mContext.getResources().openRawResource(R.raw.ssokeystore);
        keyStore.load(keyStoreStream, "<<Password>>".toCharArray());//Getting the error here even giving the right password

        trustManagerFactory.init(keyStore);
        TrustManager[] trustManagers = trustManagerFactory.getTrustManagers();
        SSLContext sc = SSLContext.getInstance("SSL");
        sc.init(null, trustManagers, null);
        HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());

可能是什么原因,我的主要用例是允许通过注册证书从应用程序进行任何 https 调用

这是堆栈跟踪

W/System.err: java.io.IOException: Wrong version of key store.
W/System.err:     at com.android.org.bouncycastle.jcajce.provider.keystore.bc.BcKeyStoreSpi.engineLoad(BcKeyStoreSpi.java:815)
W/System.err:     at java.security.KeyStore.load(KeyStore.java:1484)
W/System.err:     at net.openid.appauthdemo.TrustStoreConfiguration.ssoTtrustStore(TrustStoreConfiguration.java:32)
W/System.err:     at net.openid.appauthdemo.LoginActivity.onCreate(LoginActivity.java:117)
W/System.err:     at android.app.Activity.performCreate(Activity.java:7224)
W/System.err:     at android.app.Activity.performCreate(Activity.java:7213)
W/System.err:     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1272)
W/System.err:     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2926)
W/System.err:     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3081)
W/System.err:     at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
W/System.err:     at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
W/System.err:     at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
W/System.err:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1831)
W/System.err:     at android.os.Handler.dispatchMessage(Handler.java:106)
W/System.err:     at android.os.Looper.loop(Looper.java:201)
W/System.err:     at android.app.ActivityThread.main(ActivityThread.java:6810)
W/System.err:     at java.lang.reflect.Method.invoke(Native Method)
W/System.err:     at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
W/System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873)

4

2 回答 2

1

你的 是什么类型的KeyStore,它在什么操作系统版本上崩溃?根据 KeyStore 文档,Android 平台支持以下类型

KeyStore 类型支持

于 2020-07-25T18:06:23.540 回答
0

最简单的解决方法(保证在 Android 上工作,截至 2021 年 10 月)是从现有的 Java KeyStore 切换到 BouncyCastle KeyStore (BKS)。

打开您的 KeyStore 文件,然后使用 KeyStore Explorer(可在线下载 Mac 和 Windows 的可执行文件)切换到 BKS。

于 2021-10-22T13:11:31.853 回答