代码:
@UtilityClass public final class X509Certs { private static final CertificateFactory CERTIFICATE_FACTORY; static { try { CERTIFICATE_FACTORY = CertificateFactory.getInstance(CertificateType.X509); } catch (CertificateException e) { throw Throwables.propagate(e); } } @SneakyThrows static PublicKey getVerifyPublicKey(String signPubKeyCert) { Preconditions.checkArgument(StringUtils.isNotBlank(signPubKeyCert), "The response message doesn't contains the [signPubKeyCert]"); @Cleanup InputStream stream = new ByteArrayInputStream(signPubKeyCert.getBytes(StandardCharsets.UTF_8)); X509Certificate cert = (X509Certificate) CERTIFICATE_FACTORY.generateCertificate(stream); return cert.getPublicKey(); } }
public interface CertificateType { String X509 = "X.509"; }
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/20628.html