Created
June 9, 2020 22:31
-
-
Save shafty023/5ce14c25bc435cbc254e35313d835de2 to your computer and use it in GitHub Desktop.
Generates a random 32 byte key
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
/** | |
* 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