当前位置:   article > 正文

java实现解析SM2-DER编码证书_证书解析 java

证书解析 java

当前遇到java解析SM2,der编码格式的证书,需要解析里面字段:

  1. package com.common;
  2. import java.io.FileInputStream;
  3. import java.io.FileNotFoundException;
  4. import java.security.NoSuchProviderException;
  5. import java.security.Security;
  6. import java.security.cert.CertificateException;
  7. import java.security.cert.CertificateFactory;
  8. import java.security.cert.X509Certificate;
  9. import org.bouncycastle.jce.provider.BouncyCastleProvider;
  10. public class test {
  11. public static void main(String[] args) {
  12. Security.addProvider(new BouncyCastleProvider());
  13. String path="../src/main/resources/certs/oca.cer";
  14. try {
  15. FileInputStream fis= new FileInputStream(path);
  16. CertificateFactory cf =CertificateFactory.getInstance("X.509","BC");
  17. X509Certificate certificate=(X509Certificate) cf.generateCertificate(fis);
  18. String subjectDN= certificate.getSubjectDN().toString();
  19. String issuerDN =certificate.getIssuerDN().toString();
  20. String serialNumber= certificate.getSerialNumber().toString();
  21. System.out.println("subjectDN : "+subjectDN);
  22. System.out.println("issuerDN : "+issuerDN);
  23. System.out.println("serialNumber : "+serialNumber);
  24. } catch (FileNotFoundException |CertificateException |NoSuchProviderException e) {
  25. e.printStackTrace();
  26. }
  27. }
  28. }

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小舞很执着/article/detail/998358
推荐阅读
相关标签
  

闽ICP备14008679号