Last active
July 26, 2020 04:33
-
-
Save dinorahto/4b97bb776db0aac0058855dfc6a5c36c to your computer and use it in GitHub Desktop.
KeyPairGenerator.kt
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
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