Last active
August 1, 2017 00:48
-
-
Save d0nutptr/2ced03fb9f64e1dff2381e12f34218af to your computer and use it in GitHub Desktop.
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
public class KeyGenerationExample { | |
public generateSecretKey(String password, byte[] salt) { | |
//get the PBKDF2 HMAC SHA1 secret key factory | |
SecretKeyFactory secretKeyFactory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1"); | |
//similar to WPA2 key generation | |
KeySpec keySpec = new PBEKeySpec(password.toCharArray(), salt, 4096, 32); | |
//generate the key | |
return secretKeyFactory.generateSecret(keySpec); | |
} | |
public byte[] generateSalt() { | |
byte[] salt = new byte[32]; | |
(new SecureRandom()).nextBytes(salt); | |
return salt; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment