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

bouncycastle创建csr

时间:2014-08-14 20:12:39      阅读:175      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   os   io   ar   div   log   

public static void main(String[] args) {
        String subjectDN = "CN=duwenlei";
        String algorithm = "";
        try {
            KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("RSA");
            keyPairGenerator.initialize(2048);
            KeyPair keyPair = keyPairGenerator.generateKeyPair();
            algorithm = keyPair.getPrivate().getAlgorithm();
            PKCS10CertificationRequestBuilder builder = new PKCS10CertificationRequestBuilder(new X500Name(subjectDN)
                    ,SubjectPublicKeyInfo.getInstance(keyPair.getPublic().getEncoded()));
            
            JcaContentSignerBuilder jcaBuilder = new JcaContentSignerBuilder("sha1withrsa");
//            jcaBuilder.setProvider(provider); 这里可以添加提供者
            ContentSigner contentSigner = jcaBuilder.build(keyPair.getPrivate());
            builder.build(contentSigner);
            System.out.println(builder.toString());
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        } catch (OperatorCreationException e) {
            e.printStackTrace();
        }

    }

需要用到的包:bcmail-jdk15-1.46.jar,bcprov-jdk15-1.46.jar,用不到:bctsp-jdk15-1.46.jar

bouncycastle创建csr,布布扣,bubuko.com

bouncycastle创建csr

标签:style   blog   color   os   io   ar   div   log   

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

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