JCE 无法在 Robolectric 中验证提供者 BC

JCE cannot authenticate the provider BC in Robolectric

我正在尝试在我的应用程序中测试密钥库签名,但无法通过从资产加载密钥库,因为抛出了错误:

java.io.IOException: error constructing MAC: java.lang.SecurityException: JCE cannot authenticate the provider BC

这是代码

@Test
public void testKeyStore() {

    try {
        KeyStore keyStore = KeyStore.getInstance("PKCS12");
        InputStream inputStream = RuntimeEnvironment.application.getAssets().open(fileName);
        keyStore.load(inputStream, password.toCharArray());

    } catch (Exception e) {
        e.printStackTrace();
    }
}

如果没有 Robolectric,有人知道如何 运行 这个测试吗? 谢谢

这里真的不需要Robolectric。接下来试试:

@Test
public void testKeyStore() throws Exception {
        KeyStore keyStore = KeyStore.getInstance("PKCS12");
        String path = System.getProperty("user.dir") + "src/main/assets/filename.key";
        InputStream inputStream = TimerTest.class.getResourceAsStream(path);
        keyStore.load(inputStream, "test".toCharArray());
}