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