首页 > 代码库 > bouncycastle创建csr
bouncycastle创建csr
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
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。