1

I get a public key string from a json as :

 -----BEGIN RSA PUBLIC KEY-----
    ....
 -----END RSA PUBLIC KEY-----

I get this error when I load it :

com.android.org.conscrypt.OpenSSLX509CertificateFactory$ParsingException: Error parsing public key

I need it to be a pkcs8 in order to load it, is there any solution besides using a third library ?

I load PKCS8 like this:

   override suspend fun loadPublicKey(key: String): PublicKey {
        return withContext(Dispatchers.IO) {

            val readString = key.replace("-----BEGIN PUBLIC KEY-----", "")
                .replace("-----END PUBLIC KEY-----", "")

            val encoded = Base64.decode(readString, Base64.DEFAULT)

            KeyFactory.getInstance("RSA")
                .generatePublic(X509EncodedKeySpec(encoded))
        }
    }
Anath43ema
  • 39
  • 5

0 Answers0