我们已经看到以下异常涌入,并且仅适用于 Android 7.1.1 (API 25)。7.1.1 中是否发生了一些变化而导致失败?
java.security.ProviderException: Failed to load generated key pair from keystore
at android.security.keystore.AndroidKeyStoreKeyPairGeneratorSpi.loadKeystoreKeyPair(AndroidKeyStoreKeyPairGeneratorSpi.java:518)
at android.security.keystore.AndroidKeyStoreKeyPairGeneratorSpi.generateKeyPair(AndroidKeyStoreKeyPairGeneratorSpi.java:470)
下面的净化代码(可能有轻微的复制粘贴错误)
KeyPairGenerator generator = KeyPairGenerator.getInstance("RSA", "AndroidKeyStore");
String certInfo = String.format(Locale.ROOT, "CN=%s, OU=%s", new Object[]{"KeyName", context.getPackageName()});
generator.initialize(new KeyPairGeneratorSpec.Builder(context)).setAlias("KeyName").setSubject(new X500Principal(certInfo)).setSerialNumber(BigInteger.ONE).setStartDate(start).setEndDate(end).build());
generator.generateKeyPair();