I have created a self-signed certificate with Java code and added into KeyStore. Now I want to export Private key and Certificate created, into a file in PEM format. Is it
On Android, you can use the following Kotlin extension function:
import android.util.Base64
import java.security.PublicKey
fun PublicKey.toPemString(): String {
val publicKeyBase64: String = Base64.encodeToString(this.encoded, Base64.NO_WRAP)
return publicKeyBase64.chunked(64).joinToString(
separator = "\n",
prefix = "-----BEGIN PUBLIC KEY-----\n",
postfix = "\n-----END PUBLIC KEY-----\n"
)
}