2015-09-05 46 views
1

我想在我的應用程序來測試一個密鑰簽名,但不能越過加載從資產密鑰庫,因爲錯誤被拋出:JCE無法驗證提供商公元前Robolectric

java.io. IOException異常:錯誤構建MAC: java.lang.SecurityException異常:JCE不能驗證提供商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,有沒有人有一個想法如何運行這個測試? 謝謝

+0

你想要測試什麼?您實際上不需要Robolectric這個java代碼 –

回答

0

你真的不需要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()); 
} 
+0

謝謝。實際上,這樣做的確如此: String path = System.getProperty(「user.dir」)+「/src/main/assets/filename.key」; InputStream inputStream = new FileInputStream(path) ... – Goran

+0

更新了答案。我建議你刪除try/catch,因爲預計測試可能會拋出異常 –