Skip to content

Instantly share code, notes, and snippets.

@dinorahto
Last active July 26, 2020 04:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dinorahto/4b97bb776db0aac0058855dfc6a5c36c to your computer and use it in GitHub Desktop.
Save dinorahto/4b97bb776db0aac0058855dfc6a5c36c to your computer and use it in GitHub Desktop.
KeyPairGenerator.kt
KeyPairGenerator.getInstance(KeyProperties.KEY_ALGORITHM_RSA, "AndroidKeyStore").apply {
val certBuilder = KeyGenParameterSpec.Builder(alias, KeyProperties.PURPOSE_ENCRYPT)
.setKeyValidityStart(keyValidityStart)
.setKeyValidityEnd(keyValidityEnd)
.setCertificateSerialNumber(BigInteger.valueOf(1L))
.setCertificateSubject(X500Principal("CN=MyCompany"))
.setUserAuthenticationRequired(true)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
initialize(
certBuilder
.setIsStrongBoxBacked(true)
.build()
)
} else {
initialize(certBuilder.build())
}
}.also {
val keyPair = it.generateKeyPair()
//Continue here
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment