Class ClientCertificate
A TLS client credential for mutual TLS: a certificate chain and its private
key, presented to a server that asks for one. Given to a WebClient through
WebClient.setClientCertificate(ClientCertificate).
Two encodings, the two a credential is actually delivered in:
- PEM -- [#pem(byte[], byte[], String)]: the certificate (leaf first, then any intermediates) and the private key, as the text files a CA or a secrets manager hands out. The key may be in a file of its own or in the same one as the certificate.
- PKCS#12 -- [#pkcs12(byte[], String)]: the single
.p12/.pfxarchive holding both, protected by a password.
The bytes are copied in, never written to disk and never logged: toString names the encoding and nothing else, so a credential that reaches a log line by accident carries nothing secret with it.
What each runtime accepts. The packaged binary hands both encodings to
libcurl and OpenSSL, which take every PEM key format OpenSSL reads --
PKCS#8, encrypted PKCS#8 with a passphrase, traditional RSA and EC keys. The
local Java SE runtime reads PKCS#12, and PEM keys in unencrypted PKCS#8
(BEGIN PRIVATE KEY) or traditional RSA (BEGIN RSA PRIVATE KEY) form; any
other PEM key fails there with an IOException that names the conversion,
openssl pkcs8 -topk8 -nocrypt. Prefer PKCS#12 when one credential has to
work identically on both.
-
Method Summary
Modifier and TypeMethodDescriptionstatic ClientCertificateA PEM certificate chain and private key.static ClientCertificateA PKCS#12 archive holding the certificate chain and its private key.toString()The encoding only; the credential itself never reaches a string.
-
Method Details
-
pem
A PEM certificate chain and private key.
Parameters
-
certificateChain: the PEM certificate, leaf first, then any intermediates -
privateKey: the PEM private key, or null when it is incertificateChain -
passphrase: the key's passphrase, or null for an unencrypted key
-
-
pkcs12
A PKCS#12 archive holding the certificate chain and its private key.
Parameters
-
archive: the.p12/.pfxbytes -
password: the archive's password, or null for none
-
-
toString
-