Skip to content

//okhttp-tls/okhttp3.tls/HeldCertificate/Companion/decode

decode

[jvm]\

@JvmStatic

fun decode(certificateAndPrivateKeyPem: String): HeldCertificate

Decodes a multiline string that contains both a certificate and a private key, both PEM-encoded. A typical input string looks like this:

-----BEGIN CERTIFICATE-----
MIIBYTCCAQegAwIBAgIBKjAKBggqhkjOPQQDAjApMRQwEgYDVQQLEwtlbmdpbmVl
cmluZzERMA8GA1UEAxMIY2FzaC5hcHAwHhcNNzAwMTAxMDAwMDA1WhcNNzAwMTAx
MDAwMDEwWjApMRQwEgYDVQQLEwtlbmdpbmVlcmluZzERMA8GA1UEAxMIY2FzaC5h
cHAwWTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAASda8ChkQXxGELnrV/oBnIAx3dD
ocUOJfdz4pOJTP6dVQB9U3UBiW5uSX/MoOD0LL5zG3bVyL3Y6pDwKuYvfLNhoyAw
HjAcBgNVHREBAf8EEjAQhwQBAQEBgghjYXNoLmFwcDAKBggqhkjOPQQDAgNIADBF
AiAyHHg1N6YDDQiY920+cnI5XSZwEGhAtb9PYWO8bLmkcQIhAI2CfEZf3V/obmdT
yyaoEufLKVXhrTQhRfodTeigi4RX
-----END CERTIFICATE-----
-----BEGIN PRIVATE KEY-----
MEECAQAwEwYHKoZIzj0CAQYIKoZIzj0DAQcEJzAlAgEBBCA7ODT0xhGSNn4ESj6J
lu/GJQZoU9lDrCPeUcQ28tzOWw==
-----END PRIVATE KEY-----

The string should contain exactly one certificate and one private key in PKCS #8 format. It should not contain any other PEM-encoded blocks, but it may contain other text which will be ignored.

Encode a held certificate into this format by concatenating the results of certificatePem() and privateKeyPkcs8Pem().