I'm trying to create an application for Android that uses encryption to save user information and I cannot figure out what I'm doing wrong. I'm trying to create an instance of the SecretKeyFactory using the "PBKDF2WithHmacSHA1" algorithm, but the application keeps on throwing exceptions at that point in the program (it doesn't matter if it's in the emulator or on real hardware).
Code:
SecretKeyFactory secretFactory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1");
Exception:
java.security.NoSuchAlgorithmException: SecretKeyFactory PBKDF2WithHmacSHA1 implementation not found ...
Here's the weird thing... if I take this code and compile it as a regular Java application, it works... no exceptions are thrown and I can create encrypted files (and decrypt them) without errors.
I have also tried entering other algorithms (e.g. AES, PBEWithHmacSHA1AndDESede, PBEWithMD5AndDES, etc.) and they all produce the same error/exception at that line in the code (when compiling for Android).
I have the latest version of Java installed (JDK 1.6.0.18) , all updates applied to Eclipse and plug-ins, and the latest version of the Android SDK. I'm also running Windows 7 64-bit.
Please help, I have not found an answer to this in two days of Internet searching. Thanks.
It might just not be a supported algorithm or that naming of it on Android.
Have you looked around the javax.crypto classes? https://developer.android.com/reference/javax/crypto/EncryptedPrivateKeyInfo.html
Here is an example using a different algorithm if that helps. http://www.anddev.org/viewtopic.php?p=11737
btw, add a "from-irc" tag to this post to get a google response. http://android-developers.blogspot.com/2010/01/irc-offce-hours-update.html
This means the android SDK doesn't have implementation for this algorithm. You have two options:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With