secure-preferences
secure-preferences copied to clipboard
NoSuchAlgorithmException: SecretKeyFactory PBKDF2WithHmacSHA1 implementation not found
I'm getting this internal crash in all users with Samsung SCH-I705 (Samsung Tab2 7") with Adnroid 4.1.2, in the line what I'm doing this: sPrefs = new SecurePreferences(context);
I'm importing the library in gradle file: compile 'com.scottyab:secure-preferences-lib:0.1.3'
Fatal Exception: java.lang.RuntimeException: Unable to create application com.fieldaware.app.FAApplication: java.lang.IllegalStateException: java.security.NoSuchAlgorithmException: SecretKeyFactory PBKDF2WithHmacSHA1 implementation not found at android.app.ActivityThread.handleBindApplication(ActivityThread.java) at android.app.ActivityThread.access$1400(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java) at android.os.Handler.dispatchMessage(Handler.java) at android.os.Looper.loop(Looper.java) at android.app.ActivityThread.main(ActivityThread.java) at java.lang.reflect.Method.invokeNative(Method.java) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java) at dalvik.system.NativeStart.main(NativeStart.java) Caused by java.lang.IllegalStateException: java.security.NoSuchAlgorithmException: SecretKeyFactory PBKDF2WithHmacSHA1 implementation not found at com.securepreferences.SecurePreferences.(Unknown Source) at com.securepreferences.SecurePreferences.(Unknown Source) at com.securepreferences.SecurePreferences.(Unknown Source) at com.fieldaware.app.utils.Settings.(Unknown Source) at com.fieldaware.app.FAApplication.onCreate(SourceFile) at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java) at android.app.ActivityThread.handleBindApplication(ActivityThread.java) at android.app.ActivityThread.access$1400(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java) at android.os.Handler.dispatchMessage(Handler.java) at android.os.Looper.loop(Looper.java) at android.app.ActivityThread.main(ActivityThread.java) at java.lang.reflect.Method.invokeNative(Method.java) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java) at dalvik.system.NativeStart.main(NativeStart.java) Caused by java.security.NoSuchAlgorithmException: SecretKeyFactory PBKDF2WithHmacSHA1 implementation not found at org.apache.harmony.security.fortress.Engine.notFound(Engine.java) at org.apache.harmony.security.fortress.Engine.getInstance(Engine.java) at javax.crypto.SecretKeyFactory.getInstance(SecretKeyFactory.java) at com.tozny.crypto.android.AesCbcWithIntegrity.generateKeyFromPassword(SourceFile) at com.tozny.crypto.android.AesCbcWithIntegrity.generateKeyFromPassword(SourceFile) at com.securepreferences.SecurePreferences.generateAesKeyName(SourceFile) at com.securepreferences.SecurePreferences.(Unknown Source) at com.securepreferences.SecurePreferences.(Unknown Source) at com.securepreferences.SecurePreferences.(Unknown Source) at com.fieldaware.app.utils.Settings.(Unknown Source) at com.fieldaware.app.FAApplication.onCreate(SourceFile) at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java) at android.app.ActivityThread.handleBindApplication(ActivityThread.java) at android.app.ActivityThread.access$1400(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java) at android.os.Handler.dispatchMessage(Handler.java) at android.os.Looper.loop(Looper.java) at android.app.ActivityThread.main(ActivityThread.java) at java.lang.reflect.Method.invokeNative(Method.java) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java) at dalvik.system.NativeStart.main(NativeStart.java)
No issues in others devices. Is there some workaround to avoid this issue? Thanks
I got the same issue on
- Samsung Galaxy S III (gt-i9300)
- Samsung GALAXY Tab 2 7.0 (gt-p3100)
- Samsung Galaxy Note 2 (gt-n7100)`
running Android 4.1.1 or Android 4.1.2
with secure-pref version 0.1.2.
Caused by java.lang.IllegalStateException: java.security.NoSuchAlgorithmException: SecretKeyFactory PBKDF2WithHmacSHA1 implementation not found
at com.securepreferences.SecurePreferences.(Unknown Source)
at com.securepreferences.SecurePreferences.(Unknown Source)
at com.securepreferences.SecurePreferences.(Unknown Source)
at solda.io.android.util.PrefUtils.getDefaultPreference(Unknown Source)
at solda.io.android.util.PrefUtils.getProductsInShippingCart(Unknown Source)
at solda.io.android.ui.activity.DrawerActivity.restoreShoppingCart(Unknown Source)
at solda.io.android.ui.activity.DrawerActivity.onCreate(Unknown Source)
at android.app.Activity.performCreate(Activity.java:5184)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1083)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2064)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2125)
at android.app.ActivityThread.access$600(ActivityThread.java:140)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1227)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4898)
at java.lang.reflect.Method.invokeNative(Method.java)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
at dalvik.system.NativeStart.main(NativeStart.java)
Caused by java.security.NoSuchAlgorithmException: SecretKeyFactory PBKDF2WithHmacSHA1 implementation not found
at org.apache.harmony.security.fortress.Engine.notFound(Engine.java:177)
at org.apache.harmony.security.fortress.Engine.getInstance(Engine.java:151)
at javax.crypto.SecretKeyFactory.getInstance(SecretKeyFactory.java:108)
at com.tozny.crypto.android.AesCbcWithIntegrity.keys(Unknown Source)
at com.securepreferences.SecurePreferences.getSharedPreferenceFile(Unknown Source)
at com.securepreferences.SecurePreferences.(Unknown Source)
at com.securepreferences.SecurePreferences.(Unknown Source)
at com.securepreferences.SecurePreferences.(Unknown Source)
at solda.io.android.util.PrefUtils.getDefaultPreference(Unknown Source)
at solda.io.android.util.PrefUtils.getProductsInShippingCart(Unknown Source)
at solda.io.android.ui.activity.DrawerActivity.restoreShoppingCart(Unknown Source)
at solda.io.android.ui.activity.DrawerActivity.onCreate(Unknown Source)
at android.app.Activity.performCreate(Activity.java:5184)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1083)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2064)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2125)
at android.app.ActivityThread.access$600(ActivityThread.java:140)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1227)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4898)
at java.lang.reflect.Method.invokeNative(Method.java)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
at dalvik.system.NativeStart.main(NativeStart.java)
Is there anyway we can choose which implementation to use based on Android version?
@scottyab is this related? https://github.com/tozny/java-aes-crypto/issues/9
Hey @cyberrob it seems related yes, those devices don't seem to have that algorithm or the fallback algorithm ( a shame :( ). Open to PR's to solve.
We could resolve this problem by adding https://rtyley.github.io/spongycastle/ lib. Is it a single solution? Could anyone suggest better solution?
It seems like SpongyCastle would be a good solution. Who wants to put a PR in for it? :)
Any work around ? I am unable to use spongycastle in android studio, what i will have to do after adding lib in my project. also what is PR :)
@inktomi Which SpongyCastle dependencies did you include in your Android Studio gradle project?
All of them?
compile 'com.madgag.spongycastle:core:1.54.0.0'
compile 'com.madgag.spongycastle:prov:1.54.0.0'
compile 'com.madgag.spongycastle:pkix:1.54.0.0'
compile 'com.madgag.spongycastle:pg:1.54.0.0'
Any update here? Having this issue with many samsung phones, any advice on how to fix?
@brandoFS For now I've added the SpongyCastle dependency to build.gradle //SpongeCastle compile('com.madgag.spongycastle:core:1.54.0.0') compile('com.madgag.spongycastle:prov:1.54.0.0') And added it in the MyApplication class
static { Security.insertProviderAt(new org.spongycastle.jce.provider.BouncyCastleProvider(), 1); }
It's not the solution but it works. Hope that helps you as a patch for now.
@albertovelazmoliner thank you
I got it more in 4.1.2 . who can help me ??
@lgengsy please use @albertovelazmoliner solution
@albertovelazmoliner added your spongycastle dependencies but we are still seeing the crash in our latest release. Any other idea?
I want to rewrite this with other encryption。
I got the same issue... even after adding spongycastle.
That's frustrating :-(
Strange that some of you are seeing adding spongy fix this issue and some not. @PasqualePuzio & @brandoFS (or anyone else with this issue) could you paste the output of http://stackoverflow.com/a/7561104 to help debug this.
The solution should be to add spongy, but never put it past samsung to mess something up that every other device honors...
Is there any solution already? I found that in the SecurePreferencesOld already is the mechanism to detect if algorithm is supported on the running platform. Why it is nt in the new one?
Ther was problem that when user migrated to different phone they lost the configuration. But I think that used algorithm should be stored in preferences item to keep the same when new one will be introduced in the library to backward compatibility.
I am handling this like -
try {
AesCbcWithIntegrity.SecretKeys myKey = AesCbcWithIntegrity.generateKeyFromPassword(Build.SERIAL, AesCbcWithIntegrity.generateSalt(), 100);
/*SecurePreferences.Editor editor = sharedPreferences.edit();
editor.putString("realmkey", myKey.toString().substring(0, 64));
editor.commit();*/
settings.edit().putString("rm", myKey.toString().substring(0, 64)).apply();
} catch (NoSuchAlgorithmException e) {
AesCbcWithIntegrity.SecretKeys myKey = AesCbcWithIntegrity.generateKey();
if (myKey.toString().length() > 64) {
settings.edit().putString("rm", myKey.toString().substring(0, 64)).apply();
}
}
am I doing it the right way?
Recently, got the error in Samsung 4.1.2 device
@deathstroke007 Is above fix is work for Samsung 4.1.2 device?.
I haven't tested it. But it will work out since i am catching the exception and using generatekey(). Please feel free to test and intimate me with the results.