zoukankan      html  css  js  c++  java
  • PKCS10生成证书csr

    public static String genCSR(String subject, String alg,String provider)
                throws InvalidKeyException, NoSuchAlgorithmException,
                NoSuchProviderException, SignatureException, OperatorCreationException {
            String signalg="";
            int alglength=0;
            String keyAlg="";
            if(alg.toUpperCase().equals("RSA1024")){
                signalg="SHA1WithRSA";
                alglength=1024;
                keyAlg="RSA";
            }else if(alg.toUpperCase().equals("RSA2048")){
                signalg="SHA1WithRSA";
                alglength=2048;
                keyAlg="RSA";
            }else if(alg.toUpperCase().equals("SM2")){
                signalg="SM3withSM2";
                alglength=256;
                keyAlg="SM2";
            }
            KeyPairGenerator keyGen = KeyPairGenerator.getInstance(keyAlg);
            keyGen.initialize(alglength);
            KeyPair kp = keyGen.generateKeyPair();
            PKCS10CertificationRequestBuilder builder = new PKCS10CertificationRequestBuilder(new X500Name(subject),SubjectPublicKeyInfo.getInstance(kp.getPublic().getEncoded()));
            JcaContentSignerBuilder jcaContentSignerBuilder = new JcaContentSignerBuilder(signalg);
            jcaContentSignerBuilder.setProvider(provider);
            ContentSigner contentSigner = jcaContentSignerBuilder.build(kp.getPrivate());
            builder.build(contentSigner);
            return builder.toString();
        }

      一.用到的包

      1. bouncycastle:bcmail-jdk15:1.46,org.bouncycastle.pkcs public class PKCS10Certi

    如果有使用请标明来源:http://www.cnblogs.com/duwenlei/
  • 相关阅读:
    MEP工作流程
    一盘很大的棋
    老人棒子鸡
    REVIT多专业协同设计
    不做没有理想的咸鱼
    卫生间排风设计规范
    如何时刻保持在目标的正确轨道上
    OGame殖民
    OGame舰队保护(FleetSave, FS)
    在局域网内架ESS3.0升级服务器
  • 原文地址:https://www.cnblogs.com/duwenlei/p/3898929.html
Copyright © 2011-2022 走看看