Created
June 26, 2019 08:56
-
-
Save BDOMDev/1adb610ea0ed1bde4246e15af1bbb882 to your computer and use it in GitHub Desktop.
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
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
fixed
generateSecretKey
https://gist.github.com/EMCP/d307a801da0462141a3e7662a720406a