Jay*_*yas 2 android android-fingerprint-api
我在我的应用程序中使用指纹传感器.我知道api适用于棉花糖和OS以上.因此,在我的课程中运行时,我正在动态检查sdk版本.
即使是指纹不执行的代码我面临4.0 android os上的异常,而同样执行5.0及以上.
**java.lang.VerifyError: com/cloudzon/gratzeez1/GiveGratuityActivity
at java.lang.Class.newInstanceImpl(Native Method)
at java.lang.Class.newInstance(Class.java:1215)
at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2265)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2417)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1342)
at android.os.Handler.dispatchMessage(Handler.java:110)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:5322)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:829)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:645)
at dalvik.system.NativeStart.main(Native Method)**
Run Code Online (Sandbox Code Playgroud)
我发现由于我班上的代码如下,我正面临着这个问题.
public boolean cipherInit() {
try {
cipher = Cipher.getInstance(KeyProperties.KEY_ALGORITHM_AES + "/" + KeyProperties.BLOCK_MODE_CBC + "/" + KeyProperties.ENCRYPTION_PADDING_PKCS7);
} catch (NoSuchAlgorithmException | NoSuchPaddingException e) {
throw new RuntimeException("Failed to get Cipher", e);
}
try {
keyStore.load(null);
SecretKey key = (SecretKey) keyStore.getKey(KEY_NAME,
null);
cipher.init(Cipher.ENCRYPT_MODE, key);
return true;
} catch (KeyPermanentlyInvalidatedException e) {
return false;
} catch (KeyStoreException | CertificateException | UnrecoverableKeyException | IOException | NoSuchAlgorithmException | InvalidKeyException e) {
throw new RuntimeException("Failed to init Cipher", e);
}
}
Run Code Online (Sandbox Code Playgroud)
小智 7
我也碰到了这个,另一个回答让我走上正轨; 如何在较低平台版本中使用不受支持的异常
我改变那个方法;
public boolean cipherInit() {
try {
cipher = Cipher.getInstance(KeyProperties.KEY_ALGORITHM_AES + "/" + KeyProperties.BLOCK_MODE_CBC + "/" + KeyProperties.ENCRYPTION_PADDING_PKCS7);
} catch (NoSuchAlgorithmException | NoSuchPaddingException e) {
throw new RuntimeException("Failed to get Cipher", e);
}
try {
keyStore.load(null);
SecretKey key = (SecretKey) keyStore.getKey(KEY_NAME, null);
cipher.init(Cipher.ENCRYPT_MODE, key);
return true;
} catch (Exception e) {
if(e instanceof KeyPermanentlyInvalidatedException)
return false;
else if(e instanceof KeyStoreException|e instanceof CertificateException|e instanceof UnrecoverableKeyException|e instanceof IOException|e instanceof NoSuchAlgorithmException|e instanceof InvalidKeyException)
throw new RuntimeException("Failed to init Cipher",e);
}
return false;
}
Run Code Online (Sandbox Code Playgroud)
将KeyPermanentlyInvalidatedException的catch块从(KeyPermanentlyInvalidatedException e)更改为(e instanceof KeyPermanentlyInvalidatedException)似乎由于某种原因修复了该问题.
| 归档时间: |
|
| 查看次数: |
565 次 |
| 最近记录: |