Skip to content

Instantly share code, notes, and snippets.

@BDOMDev
Created June 26, 2019 08:56
Show Gist options
  • Save BDOMDev/1adb610ea0ed1bde4246e15af1bbb882 to your computer and use it in GitHub Desktop.
Save BDOMDev/1adb610ea0ed1bde4246e15af1bbb882 to your computer and use it in GitHub Desktop.
fun getSecretKey(sharedPref: SharedPreferences): SecretKey {
val key = sharedPref.getString(AppConstants.secretKeyPref, null)
if (key == null) {
//generate secure random
val secretKey = generateSecreKey()
saveSecretKey(sharedPref, secretKey!!)
return secretKey
}
val decodedKey = Base64.decode(key, Base64.NO_WRAP)
val originalKey = SecretKeySpec(decodedKey, 0, decodedKey.size, "AES")
return originalKey
}
@EMCP
Copy link

EMCP commented Nov 12, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment