将 PEM 格式的字符串转换为 java.security.cert.X509Certificate
2022-08-31 20:26:26
如何从 PEM 格式的字符串创建实例?PEM 格式的字符串是 HTTP 请求“SSL_CLIENT_CERT”标头值。java.security.cert.X509Certificate
答:根据mgaert的答案,这是我在Scala中写的:
val cert = factory.generateCertificate(
new ByteArrayInputStream(
Base64.decodeBase64(
cert.stripPrefix("-----BEGIN CERTIFICATE-----").stripSuffix("-----END CERTIFICATE-----")
)
).asInstanceOf[X509Certificate]