Skip to content

Instantly share code, notes, and snippets.

@EMCP
Forked from BDOMDev/Utils.kt
Created November 12, 2019 22:00
Show Gist options
  • Save EMCP/5d4566aeac1468729101cbf852f7b1b6 to your computer and use it in GitHub Desktop.
Save EMCP/5d4566aeac1468729101cbf852f7b1b6 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
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment