Class PKCGenerate

java.lang.Object
org.ofdrw.gm.cert.PKCGenerate

public class PKCGenerate extends Object
生成测试的公私钥对和证书

P12文件

PK - Public Key and Private Key Pair

C - Certificate

Since:
2020-04-21 09:37:10
Author:
权观宇
  • Constructor Details

    • PKCGenerate

      public PKCGenerate()
  • Method Details

    • TestND

      public static org.bouncycastle.asn1.x500.X500Name TestND()
      Returns:
      证书请求识别名称 (也就是证书的Subject)
    • CertRequest

      public static org.bouncycastle.pkcs.PKCS10CertificationRequest CertRequest(KeyPair kp, org.bouncycastle.asn1.x500.X500Name subject) throws org.bouncycastle.operator.OperatorCreationException
      生成SM2密钥对的证书请求(pkcs10格式)
      Parameters:
      kp - SM2密钥对
      subject - 证书使用者
      Returns:
      证书请求
      Throws:
      org.bouncycastle.operator.OperatorCreationException - 操作异常
    • GenerateKeyPair

      public static KeyPair GenerateKeyPair() throws GeneralSecurityException
      生成测试SM2密钥对
      Returns:
      密钥对
      Throws:
      GeneralSecurityException - 安全操作异常
    • GenCert

      public static X509Certificate GenCert(org.bouncycastle.pkcs.PKCS10CertificationRequest p10Obj, Certificate root, PrivateKey privateKey) throws GeneralSecurityException, IOException, org.bouncycastle.operator.OperatorCreationException
      签发证书
      Parameters:
      p10Obj - 证书请求ASN1对象
      root - CA根证书
      privateKey - CA私钥
      Returns:
      X509证书对象
      Throws:
      GeneralSecurityException - 安全操作异常
      IOException - 文件读写异常
      org.bouncycastle.operator.OperatorCreationException - 操作异常
    • SaveToPKCS12

      public static void SaveToPKCS12(KeyPair pk, Certificate[] certs, String pwd, Path outP) throws GeneralSecurityException, IOException
      生成P12存储文件

      存储公私钥对以及证书

      Parameters:
      pk - 密钥对
      certs - 证书链
      pwd - P12密码
      outP - 保存位置
      Throws:
      GeneralSecurityException - 安全异常
      IOException - IO异常