# android

Guy Bieber

06/29/2020, 6:15 PM
I have a keypair generated using the AndroidOpenSSL provider as follows:
Copy code
// Get the EC key generator. Has to be the OpenSSL version
        val kpg: KeyPairGenerator = KeyPairGenerator.getInstance(
            "EC", "AndroidOpenSSL")

        val parameterSpec = ECGenParameterSpec("AndroidOpenSSL)"

        //initialize and generate the keypair
        val kp = kpg.generateKeyPair()
I need to be able to store and retrieve this using the android keystore, however there doesn’t seem to be a way get the self signed certificate needed to store the key pair:
Copy code
val certArray : Array<Certificate> = arrayOf(certificate)
            //var certPath = PublicKeyToX509Cert(keyPair.public)
            keyStore.setKeyEntry(alias, keyPair.private.encoded, certArray)
Basically the first certificate in the certArray needs to be the public key certificate. So the core question is how do I get from a publicKey to a certificate?
The CertificateFactory should be able to take in a PEM or DER encoded publicKey. It is my understanding that publicKey.encoded is in DER format.
When I print the publickey.getFormat it return X509, yet is not an x509 cert