Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PBKDF2WithHmacSHA256 on Android API 24 and lower

I'm trying to use Luke Joshua Park SecureCompatibleEncryptionExamples on android. My problem is that PBKDF2WithHmacSHA256 is not available for android below API 26. Any way to get around this?

like image 660
DCD Avatar asked Aug 31 '25 04:08

DCD


1 Answers

Android doesn't support PBKDF2withHmacSHA256 before API 26, but it does support PBKDF2withHmacSHA1 in older versions. Unless there is a specific reason you want to use SHA256 as the PBKDF2 hash, there is no harm in changing this.

The algorithms in my repository can be changed relatively easily by adjusting the PBKDF2_NAME parameter. SHA1 is still safe to use with PBKDF2, so you could simply adjust:

private final static String PBKDF2_NAME = "PBKDF2WithHmacSHA256";

To:

private final static String PBKDF2_NAME = "PBKDF2WithHmacSHA1";

In your Android code and in your PHP change:

define("PBKDF2_NAME", "sha256");

To:

define("PBKDF2_NAME", "sha1");

Also of note, if you're using this as transport security, you shouldn't be. You should be using TLS.

like image 54
Luke Joshua Park Avatar answered Sep 02 '25 18:09

Luke Joshua Park