Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android SecretKeyFactory problems. Implementation not found?

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.

like image 278
RyanM Avatar asked Feb 13 '10 07:02

RyanM


2 Answers

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

like image 84
Patrick Kafka Avatar answered Nov 06 '22 17:11

Patrick Kafka


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
like image 40
Bozho Avatar answered Nov 06 '22 16:11

Bozho