在Android 6.0上抛出java.security.ProviderException:with KeyPairGenerator.generateKeyPair()

在Android 6.0上抛出java.security.ProviderException:with KeyPairGenerator.generateKeyPair(),java,android,sqlcipher,android-security,key-pair,Java,Android,Sqlcipher,Android Security,Key Pair,在运行Android 6.0的设备上已经发生过多次崩溃,但以下情况除外。密钥生成方法正在崩溃,出现以下异常。keyPairGenerator.generateKeyPair()方法调用正在发生 *java.lang.RuntimeException: at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6320) at android.app.ActivityThread.access$1800

在运行Android 6.0的设备上已经发生过多次崩溃,但以下情况除外。密钥生成方法正在崩溃,出现以下异常。keyPairGenerator.generateKeyPair()方法调用正在发生

*java.lang.RuntimeException: 
  at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6320)
  at android.app.ActivityThread.access$1800(ActivityThread.java:221)
  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1860)
  at android.os.Handler.dispatchMessage(Handler.java:102)
  at android.os.Looper.loop(Looper.java:158)
  at android.app.ActivityThread.main(ActivityThread.java:7225)
  at java.lang.reflect.Method.invoke(Native Method:0)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Caused by: java.security.ProviderException: 
  at android.security.keystore.AndroidKeyStoreKeyPairGeneratorSpi.generateKeyPair(AndroidKeyStoreKeyPairGeneratorSpi.java:504)
  at java.security.KeyPairGenerator$KeyPairGeneratorImpl.generateKeyPair(KeyPairGenerator.java:276)
  at com.du.util.KeyStoreHelper.createKeysM(KeyStoreHelper.java:109)
  at com.du.util.KeyStoreHelper.createKeys(KeyStoreHelper.java:55)
  at com.du.util.KeyStoreHelper.getCipherPwd(KeyStoreHelper.java:242)
  at com.du.activity.DuApplication.initializeSQLCipher(DuApplication.java:272)
  at com.du.activity.DuApplication.onCreate(DuApplication.java:141)
  at com.du.activity.DuApplication_.onCreate(DuApplication_.java:21)
  at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1036)
  at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6317)*
请查找下面的代码,它在keyPairGenerator.generateKeyPair()方法处崩溃。

@TargetApi(Build.VERSION_CODES.M)
    static void createKeysM(String alias, boolean requireAuth) {
        try {
            KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance(
                    KeyProperties.KEY_ALGORITHM_RSA, SecurityConstants.KEYSTORE_PROVIDER_ANDROID_KEYSTORE);
            keyPairGenerator.initialize(
                    new KeyGenParameterSpec.Builder(
                            alias,
                            KeyProperties.PURPOSE_ENCRYPT | KeyProperties.PURPOSE_DECRYPT)
                            .setAlgorithmParameterSpec(new RSAKeyGenParameterSpec(1024, F4))
                            .setBlockModes(KeyProperties.BLOCK_MODE_CBC)
                            .setEncryptionPaddings(KeyProperties.ENCRYPTION_PADDING_RSA_PKCS1)
                            .setDigests(KeyProperties.DIGEST_SHA256,
                                    KeyProperties.DIGEST_SHA384,
                                    KeyProperties.DIGEST_SHA512)
                            // Only permit the private key to be used if the user authenticated
                            // within the last five minutes.
                            .setUserAuthenticationRequired(requireAuth)
                            .build());
            KeyPair keyPair = keyPairGenerator.generateKeyPair();
            Log.d(TAG, "Public Key is: " + keyPair.getPublic().toString());

        } catch (NoSuchProviderException | NoSuchAlgorithmException | InvalidAlgorithmParameterException e) {
            throw new RuntimeException(e);
        }
    }

你遗漏了一半的堆栈跟踪更新了整个堆栈跟踪你遗漏了一半的堆栈跟踪更新了整个堆栈跟踪