Last active
August 29, 2015 14:18
-
-
Save ricalo/03d9dee372fbb89d59b1 to your computer and use it in GitHub Desktop.
Randomly generates an encryption key for devices with API level lower than 18.
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
// Devices with API level lower than 18 must setup an encryption key. | |
if (Build.VERSION.SDK_INT < 18 && AuthenticationSettings.INSTANCE.getSecretKeyData() == null) { | |
AuthenticationSettings.INSTANCE.setSecretKey(generateSecretKey()); | |
} | |
/** | |
* Randomly generates an encryption key for devices with API level lower than 18. | |
* @return The encryption key in a 32 byte long array. | |
*/ | |
protected byte[] generateSecretKey() { | |
byte[] key = new byte[32]; | |
new SecureRandom().nextBytes(key); | |
return key; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment