views:

287

answers:

2

Hello all, 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.

+1  A: 

It might just not be a supported algorithm or that naming of it on Android.

Have you looked around the javax.crypto classes http://developer.android.com/intl/zh-TW/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

sadboy
Thank you for responding. I will try more of the other types of algorithms and post back if any work.
borg17of20
After trying out every algorithm I could find information on, it seems the only algorithm Android supports is "PBEWithMD5AndDES." Your second link provides working evidence of this. I'm going to use this for my program. Thanks.
borg17of20
+1  A: 

This means the android SDK doesn't have implementation for this algorithm. You have two options:

  • switch to another, supported algorithm (I can't find a reference, so try them manually)
  • provide your own algorithm implementation
Bozho
Thank you for responding. I found this,http://java.sun.com/javase/6/docs/technotes/guides/security/SunProviders.htmland this,http://java.sun.com/javase/6/docs/technotes/guides/security/StandardNames.html#SecretKeyFactoryfor references, but I'm not sure if they pertain to Android. I'll try more algorithms and report back.
borg17of20