Skip to content

Instantly share code, notes, and snippets.

@shafty023
Created June 9, 2020 22:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shafty023/5ce14c25bc435cbc254e35313d835de2 to your computer and use it in GitHub Desktop.
Save shafty023/5ce14c25bc435cbc254e35313d835de2 to your computer and use it in GitHub Desktop.
Generates a random 32 byte key
/**
* Generates a random 32 byte key.
*
* @return a byte array containing random values
*/
fun generateRandomKey(): ByteArray =
ByteArray(32).apply {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
SecureRandom.getInstanceStrong().nextBytes(this)
} else {
SecureRandom().nextBytes(this)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment