java 把 PEM 格式的公钥证书转换为 X.509 格式的证书详解编程语言

代码:

 
@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/tech/pnotes/20628.html

(0)
上一篇 2021年7月19日 23:36
下一篇 2021年7月19日 23:36

相关推荐

发表回复

登录后才能评论