Last active
March 6, 2019 03:39
-
-
Save aramezx/c46c8855e3e73b4a0ec8ae7850826a31 to your computer and use it in GitHub Desktop.
Generating a new PrivateKey using a KeyPairGenerator with KeyPairGeneratorSpec
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
/* | |
* Generate a new EC key pair entry in the Android Keystore by | |
* using the KeyPairGenerator API. The private key can only be | |
* used for signing or verification and only with SHA-256 or | |
* SHA-512 as the message digest. | |
*/ | |
KeyPairGenerator kpg = KeyPairGenerator.getInstance( | |
KeyProperties.KEY_ALGORITHM_EC, "AndroidKeyStore"); | |
kpg.initialize(new KeyGenParameterSpec.Builder( | |
alias, | |
KeyProperties.PURPOSE_SIGN | KeyProperties.PURPOSE_VERIFY) | |
.setDigests(KeyProperties.DIGEST_SHA256, | |
KeyProperties.DIGEST_SHA512) | |
.build()); | |
KeyPair kp = kpg.generateKeyPair(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment