Created
April 30, 2018 09:04
-
-
Save kimjj81/ef14290dbfa07ef3a7a50a30bb94241b to your computer and use it in GitHub Desktop.
PBKDF2withHmacSHA1
This file contains hidden or 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
public static String makePasswordHash(String text) { | |
byte[] salt = "yoursalt".getBytes(Charsets.UTF_8); | |
try { | |
char[] chars = text.toCharArray(); | |
final int iterations = 10; | |
// Generate a 256-bit key | |
final int outputKeyLength = 256; | |
SecretKeyFactory secretKeyFactory = SecretKeyFactory.getInstance("PBKDF2withHmacSHA1"); | |
KeySpec keySpec = new PBEKeySpec(chars, salt, iterations, outputKeyLength); | |
SecretKey secretKey = secretKeyFactory.generateSecret(keySpec); | |
//edit to your needs. | |
return text + " => " + Base64.encodeToString(salt,Base64.DEFAULT) + " | " + Base64.encodeToString(secretKey.getEncoded(),Base64.DEFAULT); | |
} catch (Exception e) { | |
Log.d("PBKDF2","Exception: Error in generating password" | |
+ Log.getStackTraceString(e)); | |
} | |
return ""; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment