Last active
November 20, 2017 19:57
-
-
Save yakivmospan/e513d869759acb9b29ac65a01488c46c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
@TargetApi(23) | |
fun createAndroidKeyStoreSymmetricKey(alias: String): SecretKey { | |
val keyGenerator = KeyGenerator.getInstance(KeyProperties.KEY_ALGORITHM_AES, "AndroidKeyStore") | |
val builder = KeyGenParameterSpec.Builder(alias, KeyProperties.PURPOSE_ENCRYPT or KeyProperties.PURPOSE_DECRYPT) | |
.setBlockModes(KeyProperties.BLOCK_MODE_CBC) | |
.setEncryptionPaddings(KeyProperties.ENCRYPTION_PADDING_PKCS7) | |
keyGenerator.init(builder.build()) | |
return keyGenerator.generateKey() | |
} | |
fun getAndroidKeyStoreSymmetricKey(alias: String): SecretKey? = keyStore.getKey(alias, null) as SecretKey? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment