Skip to content

Instantly share code, notes, and snippets.

@ricalo
Last active August 29, 2015 14:18
Show Gist options
  • Save ricalo/03d9dee372fbb89d59b1 to your computer and use it in GitHub Desktop.
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.
// 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