Skip to content

Instantly share code, notes, and snippets.

@yakivmospan
Last active November 7, 2017 08:47
Show Gist options
  • Save yakivmospan/35a4498458485803f22293d46d745718 to your computer and use it in GitHub Desktop.
Save yakivmospan/35a4498458485803f22293d46d745718 to your computer and use it in GitHub Desktop.
fun createAndroidKeyStoreAsymmetricKey(alias: String): KeyPair {
val generator = KeyPairGenerator.getInstance("RSA", "AndroidKeyStore")
if (SystemServices.hasMarshmallow()) {
initGeneratorWithKeyGenParameterSpec(generator, alias)
} else {
initGeneratorWithKeyPairGeneratorSpec(generator, alias)
}
// Generates Key with given spec and saves it to the KeyStore
return generator.generateKeyPair()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment