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";

}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM