2

I need to export the public key generated by the android Keystore in x9.63 format. The default getEncoded function returns the key in x.509 byte array format.

Update:

below is my code to generate keyPair:

final int timeout = 5 * 60;
final KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance(KeyProperties.KEY_ALGORITHM_EC, "AndroidKeyStore");
final KeyGenParameterSpec.Builder builder = new KeyGenParameterSpec.Builder(keyName, KeyProperties.PURPOSE_SIGN)
        .setAlgorithmParameterSpec(new ECGenParameterSpec("secp256r1"))
        .setDigests(KeyProperties.DIGEST_SHA256,
                KeyProperties.DIGEST_SHA384,
                KeyProperties.DIGEST_SHA512)
        .setUserAuthenticationRequired(true)
        .setUserAuthenticationValidityDurationSeconds(timeout)
        .setKeySize(256);
keyPairGenerator.initialize(builder.build());
final KeyPair keyPair = keyPairGenerator.generateKeyPair();
final PublicKey publicKey = keyPair.getPublic();

here publicKey.getEncoded() returns a byte array of length 91 which is x9.62 representation of the public key. what I need is a byte array of length 65 which is x9.63 representation of the public key.

0 Answers0