Created
November 13, 2013 03:16
-
-
Save tjohns/7443106 to your computer and use it in GitHub Desktop.
Code snippet providing pre-4.4 compatibility for Android apps using SecretKeyFactory with PBKDF2WithSHA1.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.os.Build; | |
SecretKeyFactory factory; | |
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { | |
// Use compatibility key factory -- only uses lower 8-bits of passphrase chars | |
factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1And8bit"); | |
Log.i(TAG, "Selected KITKAT key factory"); | |
} else { | |
// Traditional key factory. Will use lower 8-bits of passphrase chars on older | |
// devices, and all available bits on KitKat (or newer) devices. | |
factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1"); | |
Log.i(TAG, "Selected LEGACY key factory"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
May that result in different keys generated on different devices/Android versions? If yes, there'll be trouble when users install an application prior to KitKat and then upgrade their device.