码迷,mamicode.com
首页 > 其他好文 > 详细

PKCS10生成证书csr

时间:2014-08-08 12:35:55      阅读:5055      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   os   io   div   new   log   

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

PKCS10生成证书csr,布布扣,bubuko.com

PKCS10生成证书csr

标签:style   blog   color   os   io   div   new   log   

原文地址:http://www.cnblogs.com/duwenlei/p/3898929.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!