org.bouncycastle.pkcs.jcajce.JcaPKCS10CertificationRequestBuilder Java Examples
The following examples show how to use
org.bouncycastle.pkcs.jcajce.JcaPKCS10CertificationRequestBuilder.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CsrBuilderImpl.java From java-certificate-authority with Apache License 2.0 | 7 votes |
@Override public CsrWithPrivateKey generateRequest(final DistinguishedName dn) { final KeyPair pair = KeysUtil.generateKeyPair(); try { final PrivateKey privateKey = pair.getPrivate(); final PublicKey publicKey = pair.getPublic(); final X500Name x500Name = dn.getX500Name(); final ContentSigner signGen = new JcaContentSignerBuilder(SIGNATURE_ALGORITHM) .build(privateKey); final PKCS10CertificationRequestBuilder builder = new JcaPKCS10CertificationRequestBuilder( x500Name, publicKey); final PKCS10CertificationRequest csr = builder.build(signGen); return new CsrWithPrivateKeyImpl(csr, privateKey); } catch (final OperatorCreationException e) { throw new CaException(e); } }
Example #2
Source File: TestDefaultProfile.java From hadoop-ozone with Apache License 2.0 | 6 votes |
/** * Generates an CSR with the extension specified. * This function is used to get an Invalid CSR and test that PKI profile * rejects these invalid extensions, Hence the function name, by itself it * is a well formed CSR, but our PKI profile will treat it as invalid CSR. * * @param kPair - Key Pair. * @return CSR - PKCS10CertificationRequest * @throws OperatorCreationException - on Error. */ private PKCS10CertificationRequest getInvalidCSR(KeyPair kPair, Extensions extensions) throws OperatorCreationException { X500NameBuilder namebuilder = new X500NameBuilder(X500Name.getDefaultStyle()); namebuilder.addRDN(BCStyle.CN, "invalidCert"); PKCS10CertificationRequestBuilder p10Builder = new JcaPKCS10CertificationRequestBuilder(namebuilder.build(), keyPair.getPublic()); p10Builder.addAttribute(PKCSObjectIdentifiers.pkcs_9_at_extensionRequest, extensions); JcaContentSignerBuilder csBuilder = new JcaContentSignerBuilder(this.securityConfig.getSignatureAlgo()); ContentSigner signer = csBuilder.build(keyPair.getPrivate()); return p10Builder.build(signer); }
Example #3
Source File: TlsHelper.java From localization_nifi with Apache License 2.0 | 6 votes |
public static JcaPKCS10CertificationRequest generateCertificationRequest(String requestedDn, String domainAlternativeNames, KeyPair keyPair, String signingAlgorithm) throws OperatorCreationException { JcaPKCS10CertificationRequestBuilder jcaPKCS10CertificationRequestBuilder = new JcaPKCS10CertificationRequestBuilder(new X500Name(requestedDn), keyPair.getPublic()); // add Subject Alternative Name(s) if(StringUtils.isNotBlank(domainAlternativeNames)) { try { jcaPKCS10CertificationRequestBuilder.addAttribute(PKCSObjectIdentifiers.pkcs_9_at_extensionRequest, createDomainAlternativeNamesExtensions(domainAlternativeNames)); } catch (IOException e) { throw new OperatorCreationException("Error while adding " + domainAlternativeNames + " as Subject Alternative Name.", e); } } JcaContentSignerBuilder jcaContentSignerBuilder = new JcaContentSignerBuilder(signingAlgorithm); return new JcaPKCS10CertificationRequest(jcaPKCS10CertificationRequestBuilder.build(jcaContentSignerBuilder.build(keyPair.getPrivate()))); }
Example #4
Source File: CertificateSignRequest.java From hadoop-ozone with Apache License 2.0 | 6 votes |
private PKCS10CertificationRequest generateCSR() throws OperatorCreationException { X500Name dnName = SecurityUtil.getDistinguishedName(subject, scmID, clusterID); PKCS10CertificationRequestBuilder p10Builder = new JcaPKCS10CertificationRequestBuilder(dnName, keyPair.getPublic()); ContentSigner contentSigner = new JcaContentSignerBuilder(config.getSignatureAlgo()) .setProvider(config.getProvider()) .build(keyPair.getPrivate()); if (extensions != null) { p10Builder.addAttribute( PKCSObjectIdentifiers.pkcs_9_at_extensionRequest, extensions); } return p10Builder.build(contentSigner); }
Example #5
Source File: X509CertUtil.java From portecle with GNU General Public License v2.0 | 5 votes |
/** * Create a PKCS #10 certification request (CSR) using the supplied certificate and private key. * * @param cert The certificate * @param privateKey The private key * @throws CryptoException If there was a problem generating the CSR * @return The CSR */ public static PKCS10CertificationRequest generatePKCS10CSR(X509Certificate cert, PrivateKey privateKey) throws CryptoException { X500Name subject = new X500Name(cert.getSubjectDN().toString()); JcaPKCS10CertificationRequestBuilder csrBuilder = new JcaPKCS10CertificationRequestBuilder(subject, cert.getPublicKey()); JcaContentSignerBuilder signerBuilder = new JcaContentSignerBuilder(cert.getSigAlgName()); try { ContentVerifierProvider prov = new JcaContentVerifierProviderBuilder().build(cert); PKCS10CertificationRequest csr = csrBuilder.build(signerBuilder.build(privateKey)); if (!csr.isSignatureValid(prov)) { throw new CryptoException(RB.getString("NoVerifyGenCsr.exception.message")); } return csr; } catch (OperatorCreationException | PKCSException ex) { throw new CryptoException(RB.getString("NoGenerateCsr.exception.message"), ex); } }
Example #6
Source File: IdentityController.java From Spark with Apache License 2.0 | 5 votes |
/** * Creates Certificate Signing Request. * * @throws IOException * @throws OperatorCreationException */ public PKCS10CertificationRequest createCSR(KeyPair keyPair) throws IOException, OperatorCreationException { X500Principal principal = new X500Principal(createX500NameString()); PKCS10CertificationRequestBuilder p10Builder = new JcaPKCS10CertificationRequestBuilder(principal, keyPair.getPublic()); JcaContentSignerBuilder csBuilder = new JcaContentSignerBuilder("SHA256withRSA"); ContentSigner signer = csBuilder.build(keyPair.getPrivate()); PKCS10CertificationRequest csr = p10Builder.build(signer); return csr; }
Example #7
Source File: TlsHelper.java From nifi with Apache License 2.0 | 5 votes |
public static JcaPKCS10CertificationRequest generateCertificationRequest(String requestedDn, List<String> domainAlternativeNames, KeyPair keyPair, String signingAlgorithm) throws OperatorCreationException { JcaPKCS10CertificationRequestBuilder jcaPKCS10CertificationRequestBuilder = new JcaPKCS10CertificationRequestBuilder(new X500Name(requestedDn), keyPair.getPublic()); // add Subject Alternative Name(s) try { jcaPKCS10CertificationRequestBuilder.addAttribute(PKCSObjectIdentifiers.pkcs_9_at_extensionRequest, createDomainAlternativeNamesExtensions(domainAlternativeNames, requestedDn)); } catch (IOException e) { throw new OperatorCreationException("Error while adding " + domainAlternativeNames + " as Subject Alternative Name.", e); } JcaContentSignerBuilder jcaContentSignerBuilder = new JcaContentSignerBuilder(signingAlgorithm); return new JcaPKCS10CertificationRequest(jcaPKCS10CertificationRequestBuilder.build(jcaContentSignerBuilder.build(keyPair.getPrivate()))); }
Example #8
Source File: PkiUtil.java From cloudbreak with Apache License 2.0 | 5 votes |
private static PKCS10CertificationRequest generateCsrWithName(KeyPair identity, String name, List<String> sanList) throws Exception { X500Principal principal = new X500Principal(name); PKCS10CertificationRequestBuilder p10Builder = new JcaPKCS10CertificationRequestBuilder(principal, identity.getPublic()); if (!CollectionUtils.isEmpty(sanList)) { p10Builder = addSubjectAlternativeNames(p10Builder, sanList); } JcaContentSignerBuilder csBuilder = new JcaContentSignerBuilder("SHA256withRSA"); ContentSigner signer = csBuilder.build(identity.getPrivate()); return p10Builder.build(signer); }
Example #9
Source File: X509Utils.java From acme-client with Apache License 2.0 | 5 votes |
public static PKCS10CertificationRequest generateCSR(String[] commonNames, KeyPair pair) throws OperatorCreationException, IOException { X500NameBuilder namebuilder = new X500NameBuilder(X500Name.getDefaultStyle()); namebuilder.addRDN(BCStyle.CN, commonNames[0]); List<GeneralName> subjectAltNames = new ArrayList<>(commonNames.length); for (String cn:commonNames) subjectAltNames.add(new GeneralName(GeneralName.dNSName, cn)); GeneralNames subjectAltName = new GeneralNames(subjectAltNames.toArray(new GeneralName[0])); ExtensionsGenerator extGen = new ExtensionsGenerator(); extGen.addExtension(Extension.subjectAlternativeName, false, subjectAltName.toASN1Primitive()); PKCS10CertificationRequestBuilder p10Builder = new JcaPKCS10CertificationRequestBuilder(namebuilder.build(), pair.getPublic()); p10Builder.addAttribute(PKCSObjectIdentifiers.pkcs_9_at_extensionRequest, extGen.generate()); JcaContentSignerBuilder csBuilder = new JcaContentSignerBuilder("SHA256withRSA"); ContentSigner signer = csBuilder.build(pair.getPrivate()); PKCS10CertificationRequest request = p10Builder.build(signer); return request; }
Example #10
Source File: DViewPem.java From keystore-explorer with GNU General Public License v3.0 | 5 votes |
public static void main(String[] args) throws Exception { KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA", "BC"); KeyPair keyPair = keyGen.genKeyPair(); JcaPKCS10CertificationRequestBuilder csrBuilder = new JcaPKCS10CertificationRequestBuilder( new X500Name("cn=test"), keyPair.getPublic()); PKCS10CertificationRequest csr = csrBuilder .build(new JcaContentSignerBuilder("SHA256withRSA").setProvider("BC").build(keyPair.getPrivate())); DViewPem dialog = new DViewPem(new javax.swing.JFrame(), "Title", csr); DialogViewer.run(dialog); }
Example #11
Source File: DSignCsr.java From keystore-explorer with GNU General Public License v3.0 | 5 votes |
public static void main(String[] args) throws Exception { KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA", "BC"); keyGen.initialize(1024); KeyPair keyPair = keyGen.genKeyPair(); JcaPKCS10CertificationRequestBuilder csrBuilder = new JcaPKCS10CertificationRequestBuilder( new X500Name("cn=test"), keyPair.getPublic()); PKCS10CertificationRequest csr = csrBuilder .build(new JcaContentSignerBuilder("SHA256withRSA").setProvider("BC").build(keyPair.getPrivate())); DSignCsr dialog = new DSignCsr(new javax.swing.JFrame(), csr, new File(System.getProperty("user.dir"), "test.csr"), keyPair.getPrivate(), KeyPairType.RSA, null); DialogViewer.run(dialog); }
Example #12
Source File: DViewCsr.java From keystore-explorer with GNU General Public License v3.0 | 5 votes |
public static void main(String[] args) throws Exception { KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA", "BC"); KeyPair keyPair = keyGen.genKeyPair(); JcaPKCS10CertificationRequestBuilder csrBuilder = new JcaPKCS10CertificationRequestBuilder( new X500Name("cn=test"), keyPair.getPublic()); PKCS10CertificationRequest csr = csrBuilder .build(new JcaContentSignerBuilder("SHA256withRSA").setProvider("BC").build(keyPair.getPrivate())); DViewCsr dialog = new DViewCsr(new javax.swing.JFrame(), "Title", csr); DialogViewer.run(dialog); }
Example #13
Source File: Crypto.java From athenz with Apache License 2.0 | 5 votes |
public static String generateX509CSR(PrivateKey privateKey, PublicKey publicKey, String x500Principal, GeneralName[] sanArray) throws OperatorCreationException, IOException { // Create Distinguished Name X500Principal subject = new X500Principal(x500Principal); // Create ContentSigner JcaContentSignerBuilder csBuilder = new JcaContentSignerBuilder(Crypto.RSA_SHA256); ContentSigner signer = csBuilder.build(privateKey); // Create the CSR PKCS10CertificationRequestBuilder p10Builder = new JcaPKCS10CertificationRequestBuilder( subject, publicKey); // Add SubjectAlternativeNames (SAN) if specified ///CLOVER:OFF if (sanArray != null) { ///CLOVER:ON ExtensionsGenerator extGen = new ExtensionsGenerator(); GeneralNames subjectAltNames = new GeneralNames(sanArray); extGen.addExtension(Extension.subjectAlternativeName, false, subjectAltNames); p10Builder.addAttribute(PKCSObjectIdentifiers.pkcs_9_at_extensionRequest, extGen.generate()); } PKCS10CertificationRequest csr = p10Builder.build(signer); // write to openssl PEM format PemObject pemObject = new PemObject("CERTIFICATE REQUEST", csr.getEncoded()); StringWriter strWriter; try (JcaPEMWriter pemWriter = new JcaPEMWriter(strWriter = new StringWriter())) { pemWriter.writeObject(pemObject); } return strWriter.toString(); }
Example #14
Source File: CertificateAuthorityClientTest.java From dcos-commons with Apache License 2.0 | 5 votes |
private byte[] createCSR() throws IOException, OperatorCreationException { KeyPair keyPair = KEY_PAIR_GENERATOR.generateKeyPair(); X500Name name = new X500NameBuilder() .addRDN(BCStyle.CN, "issuer") .build(); ExtensionsGenerator extensionsGenerator = new ExtensionsGenerator(); extensionsGenerator.addExtension( Extension.keyUsage, true, new KeyUsage(KeyUsage.digitalSignature)); extensionsGenerator.addExtension( Extension.extendedKeyUsage, true, new ExtendedKeyUsage( new KeyPurposeId[] { KeyPurposeId.id_kp_clientAuth, KeyPurposeId.id_kp_serverAuth } )); GeneralNames subAtlNames = new GeneralNames( new GeneralName[]{ new GeneralName(GeneralName.dNSName, "test.com"), new GeneralName(GeneralName.iPAddress, TEST_IP_ADDR), } ); extensionsGenerator.addExtension( Extension.subjectAlternativeName, true, subAtlNames); ContentSigner signer = new JcaContentSignerBuilder("SHA256withRSA").build(keyPair.getPrivate()); PKCS10CertificationRequestBuilder csrBuilder = new JcaPKCS10CertificationRequestBuilder(name, keyPair.getPublic()) .addAttribute(PKCSObjectIdentifiers.pkcs_9_at_extensionRequest, extensionsGenerator.generate()); return PEMUtils.toPEM(csrBuilder.build(signer)); }
Example #15
Source File: TLSArtifactsGenerator.java From dcos-commons with Apache License 2.0 | 5 votes |
@SuppressWarnings("checkstyle:ThrowsCount") private static byte[] generateCSR( KeyPair keyPair, CertificateNamesGenerator certificateNamesGenerator) throws IOException, OperatorCreationException { ExtensionsGenerator extensionsGenerator = new ExtensionsGenerator(); extensionsGenerator .addExtension(Extension.keyUsage, true, new KeyUsage(KeyUsage.digitalSignature)); extensionsGenerator.addExtension( Extension.extendedKeyUsage, true, new ExtendedKeyUsage( new KeyPurposeId[]{ KeyPurposeId.id_kp_clientAuth, KeyPurposeId.id_kp_serverAuth, } )); extensionsGenerator.addExtension( Extension.subjectAlternativeName, true, certificateNamesGenerator.getSANs() ); PKCS10CertificationRequest csr = new JcaPKCS10CertificationRequestBuilder( certificateNamesGenerator.getSubject(), keyPair.getPublic()) .addAttribute( PKCSObjectIdentifiers.pkcs_9_at_extensionRequest, extensionsGenerator.generate() ) .build( new JcaContentSignerBuilder("SHA256withRSA") .build(keyPair.getPrivate()) ); return PEMUtils.toPEM(csr); }
Example #16
Source File: CertificateUtils.java From freehealth-connector with GNU Affero General Public License v3.0 | 5 votes |
public static byte[] createCSR(DistinguishedName distingueshedName, KeyPair keyPair) { String csrSignatureAlgorithm = RaPropertiesLoader.getProperty("csr.signature.algorithm"); try { X500Principal x500Principal = new X500Principal(distingueshedName.asNormalizedEhealthDN()); JcaPKCS10CertificationRequestBuilder csrBuilder = new JcaPKCS10CertificationRequestBuilder(x500Principal, keyPair.getPublic()); PKCS10CertificationRequest csr = csrBuilder.build((new JcaContentSignerBuilder(csrSignatureAlgorithm)).setProvider(new BouncyCastleProvider()).build(keyPair.getPrivate())); return csr.getEncoded(); } catch (OperatorCreationException var6) { throw new IllegalArgumentException(var6); } catch (IOException var7) { throw new IllegalArgumentException(var7); } }
Example #17
Source File: PKCGenerate.java From ofdrw with Apache License 2.0 | 5 votes |
/** * 生成SM2密钥对的证书请求(pkcs10格式) * * @param kp SM2密钥对 * @param subject 证书使用者 * @return 证书请求 * @throws OperatorCreationException */ public static PKCS10CertificationRequest CertRequest(KeyPair kp, X500Name subject) throws OperatorCreationException { // 构造请求信息,主要是由“实体”的DN和公钥构成 PKCS10CertificationRequestBuilder requestBuilder = new JcaPKCS10CertificationRequestBuilder(subject, kp.getPublic()); // 使用“实体”私钥对请求的信息进行签名,然后组装成ASN.1对象 return requestBuilder.build( new JcaContentSignerBuilder("SM3withSM2") .setProvider("BC") .build(kp.getPrivate())); }
Example #18
Source File: CertUtil.java From littleca with Apache License 2.0 | 5 votes |
/** * 创建ca私钥签名证书 * * @param publicKey * @param privateKey * @param issuerDN * @param userDN * @param notBefore * @param notAfter * @param serialNumber * @param signAlg * @return * @throws CertException */ public static X509Certificate makeUserCert(PublicKey publicKey, PublicKey caPublicKey, PrivateKey caPrivateKey, String issuerDN, String userDN, Date notBefore, Date notAfter, BigInteger serialNumber, String signAlg) throws CertException { try { if (null == signAlg) { throw new CertException(signAlg + " can't be null"); } X500Name issuer = new X500Name(issuerDN); //1. 创建签名 ContentSigner signer = new JcaContentSignerBuilder(signAlg) .setProvider(BouncyCastleProvider.PROVIDER_NAME).build(caPrivateKey); //2. 创建证书请求 PKCS10CertificationRequestBuilder pkcs10CertificationRequestBuilder = new JcaPKCS10CertificationRequestBuilder(new X500Name(userDN), publicKey); PKCS10CertificationRequest pkcs10CertificationRequest = pkcs10CertificationRequestBuilder.build(signer); //3. 创建证书 //SubjectPublicKeyInfo subPubKeyInfo = SubjectPublicKeyInfo.getInstance(publicKey.getEncoded()); SubjectPublicKeyInfo subPubKeyInfo = pkcs10CertificationRequest.getSubjectPublicKeyInfo(); X509v3CertificateBuilder certBuilder = new X509v3CertificateBuilder(issuer, serialNumber, notBefore, notAfter, pkcs10CertificationRequest.getSubject(), subPubKeyInfo); //添加扩展信息 见 X509CertExtensions X509CertExtensions.buildAllExtensions(certBuilder, publicKey, caPublicKey); X509CertificateHolder holder = certBuilder.build(signer); return new JcaX509CertificateConverter().setProvider(BouncyCastleProvider.PROVIDER_NAME) .getCertificate(holder); } catch (Exception e) { throw new CertException("makeUserCert failed", e); } }
Example #19
Source File: CertUtil.java From littleca with Apache License 2.0 | 5 votes |
/** * 创建一个自签名的证书 * * @param publicKey * @param privateKey * @param userDN * @param notBefore * @param notAfter * @param serialNumber * @param signAlg * @return * @throws CertException */ public static X509Certificate makeUserSelfSignCert(PublicKey publicKey, PrivateKey privateKey, String userDN, Date notBefore, Date notAfter, BigInteger serialNumber, String signAlg) throws CertException { try { if (null == signAlg) { throw new CertException(signAlg + " can't be null"); } X500Name issuer = new X500Name(userDN); //1. 创建签名 ContentSigner signer = new JcaContentSignerBuilder(signAlg) .setProvider(BouncyCastleProvider.PROVIDER_NAME).build(privateKey); //2. 创建证书请求 PKCS10CertificationRequestBuilder pkcs10CertificationRequestBuilder = new JcaPKCS10CertificationRequestBuilder(issuer, publicKey); PKCS10CertificationRequest pkcs10CertificationRequest = pkcs10CertificationRequestBuilder.build(signer); //3. 创建证书 //SubjectPublicKeyInfo subPubKeyInfo = SubjectPublicKeyInfo.getInstance(publicKey.getEncoded()); X509v3CertificateBuilder certBuilder = new X509v3CertificateBuilder(issuer, serialNumber, notBefore, notAfter, pkcs10CertificationRequest.getSubject(), pkcs10CertificationRequest.getSubjectPublicKeyInfo()); //添加扩展信息 见 X509CertExtensions X509CertExtensions.buildAllExtensions(certBuilder, publicKey, publicKey); X509CertificateHolder holder = certBuilder.build(signer); return new JcaX509CertificateConverter().setProvider(BouncyCastleProvider.PROVIDER_NAME) .getCertificate(holder); } catch (Exception e) { throw new CertException("makeUserSelfSignCert failed", e); } }
Example #20
Source File: CommonUtil.java From gmhelper with Apache License 2.0 | 5 votes |
public static PKCS10CertificationRequest createCSR(X500Name subject, SM2PublicKey pubKey, PrivateKey priKey, String signAlgo) throws OperatorCreationException { PKCS10CertificationRequestBuilder csrBuilder = new JcaPKCS10CertificationRequestBuilder(subject, pubKey); ContentSigner signerBuilder = new JcaContentSignerBuilder(signAlgo) .setProvider(BouncyCastleProvider.PROVIDER_NAME).build(priKey); return csrBuilder.build(signerBuilder); }
Example #21
Source File: CertificateUtils.java From freehealth-connector with GNU Affero General Public License v3.0 | 5 votes |
public static byte[] createCSR(String dn, KeyPair keyPair) { String csrSignatureAlgorithm = RaPropertiesLoader.getProperty("csr.signature.algorithm"); try { X500Principal x500Principal = new X500Principal(dn); JcaPKCS10CertificationRequestBuilder csrBuilder = new JcaPKCS10CertificationRequestBuilder(x500Principal, keyPair.getPublic()); PKCS10CertificationRequest csr = csrBuilder.build((new JcaContentSignerBuilder(csrSignatureAlgorithm)).setProvider(new BouncyCastleProvider()).build(keyPair.getPrivate())); return csr.getEncoded(); } catch (OperatorCreationException | IOException ex) { throw new IllegalArgumentException(ex); } }
Example #22
Source File: CertificateUtils.java From freehealth-connector with GNU Affero General Public License v3.0 | 5 votes |
public static byte[] createCSR(DistinguishedName distingueshedName, KeyPair keyPair) { String csrSignatureAlgorithm = RaPropertiesLoader.getProperty("csr.signature.algorithm"); try { X500Principal x500Principal = new X500Principal(distingueshedName.asNormalizedEhealthDN()); JcaPKCS10CertificationRequestBuilder csrBuilder = new JcaPKCS10CertificationRequestBuilder(x500Principal, keyPair.getPublic()); PKCS10CertificationRequest csr = csrBuilder.build((new JcaContentSignerBuilder(csrSignatureAlgorithm)).setProvider(new BouncyCastleProvider()).build(keyPair.getPrivate())); return csr.getEncoded(); } catch (OperatorCreationException | IOException ex) { throw new IllegalArgumentException(ex); } }
Example #23
Source File: CertificateUtils.java From freehealth-connector with GNU Affero General Public License v3.0 | 5 votes |
public static byte[] createCSR(DistinguishedName distingueshedName, KeyPair keyPair) { String csrSignatureAlgorithm = RaPropertiesLoader.getProperty("csr.signature.algorithm"); try { X500Principal x500Principal = new X500Principal(distingueshedName.asNormalizedEhealthDN()); JcaPKCS10CertificationRequestBuilder csrBuilder = new JcaPKCS10CertificationRequestBuilder(x500Principal, keyPair.getPublic()); PKCS10CertificationRequest csr = csrBuilder.build((new JcaContentSignerBuilder(csrSignatureAlgorithm)).setProvider(new BouncyCastleProvider()).build(keyPair.getPrivate())); return csr.getEncoded(); } catch (OperatorCreationException var6) { throw new IllegalArgumentException(var6); } catch (IOException var7) { throw new IllegalArgumentException(var7); } }
Example #24
Source File: CertificateUtils.java From freehealth-connector with GNU Affero General Public License v3.0 | 5 votes |
public static byte[] createCSR(DistinguishedName distingueshedName, KeyPair keyPair) { String csrSignatureAlgorithm = RaPropertiesLoader.getProperty("csr.signature.algorithm"); try { X500Principal x500Principal = new X500Principal(distingueshedName.asNormalizedEhealthDN()); JcaPKCS10CertificationRequestBuilder csrBuilder = new JcaPKCS10CertificationRequestBuilder(x500Principal, keyPair.getPublic()); PKCS10CertificationRequest csr = csrBuilder.build((new JcaContentSignerBuilder(csrSignatureAlgorithm)).setProvider(new BouncyCastleProvider()).build(keyPair.getPrivate())); return csr.getEncoded(); } catch (OperatorCreationException var6) { throw new IllegalArgumentException(var6); } catch (IOException var7) { throw new IllegalArgumentException(var7); } }
Example #25
Source File: CertificateUtils.java From freehealth-connector with GNU Affero General Public License v3.0 | 5 votes |
public static byte[] createCSR(String dn, KeyPair keyPair) { String csrSignatureAlgorithm = RaPropertiesLoader.getProperty("csr.signature.algorithm"); try { X500Principal x500Principal = new X500Principal(dn); JcaPKCS10CertificationRequestBuilder csrBuilder = new JcaPKCS10CertificationRequestBuilder(x500Principal, keyPair.getPublic()); PKCS10CertificationRequest csr = csrBuilder.build((new JcaContentSignerBuilder(csrSignatureAlgorithm)).setProvider(new BouncyCastleProvider()).build(keyPair.getPrivate())); return csr.getEncoded(); } catch (OperatorCreationException var6) { throw new IllegalArgumentException(var6); } catch (IOException var7) { throw new IllegalArgumentException(var7); } }
Example #26
Source File: CertificateUtils.java From freehealth-connector with GNU Affero General Public License v3.0 | 5 votes |
public static byte[] createCSR(DistinguishedName distingueshedName, KeyPair keyPair) { String csrSignatureAlgorithm = RaPropertiesLoader.getProperty("csr.signature.algorithm"); try { X500Principal x500Principal = new X500Principal(distingueshedName.asNormalizedEhealthDN()); JcaPKCS10CertificationRequestBuilder csrBuilder = new JcaPKCS10CertificationRequestBuilder(x500Principal, keyPair.getPublic()); PKCS10CertificationRequest csr = csrBuilder.build((new JcaContentSignerBuilder(csrSignatureAlgorithm)).setProvider(new BouncyCastleProvider()).build(keyPair.getPrivate())); return csr.getEncoded(); } catch (OperatorCreationException var6) { throw new IllegalArgumentException(var6); } catch (IOException var7) { throw new IllegalArgumentException(var7); } }
Example #27
Source File: CertificateUtils.java From freehealth-connector with GNU Affero General Public License v3.0 | 5 votes |
public static byte[] createCSR(String dn, KeyPair keyPair) { String csrSignatureAlgorithm = RaPropertiesLoader.getProperty("csr.signature.algorithm"); try { X500Principal x500Principal = new X500Principal(dn); JcaPKCS10CertificationRequestBuilder csrBuilder = new JcaPKCS10CertificationRequestBuilder(x500Principal, keyPair.getPublic()); PKCS10CertificationRequest csr = csrBuilder.build((new JcaContentSignerBuilder(csrSignatureAlgorithm)).setProvider(new BouncyCastleProvider()).build(keyPair.getPrivate())); return csr.getEncoded(); } catch (OperatorCreationException var6) { throw new IllegalArgumentException(var6); } catch (IOException var7) { throw new IllegalArgumentException(var7); } }
Example #28
Source File: CryptoPrimitives.java From fabric-sdk-java with Apache License 2.0 | 4 votes |
/** * generateCertificationRequest * * @param subject The subject to be added to the certificate * @param pair Public private key pair * @return PKCS10CertificationRequest Certificate Signing Request. * @throws OperatorCreationException */ public String generateCertificationRequest(String subject, KeyPair pair) throws InvalidArgumentException { try { PKCS10CertificationRequestBuilder p10Builder = new JcaPKCS10CertificationRequestBuilder( new X500Principal("CN=" + subject), pair.getPublic()); JcaContentSignerBuilder csBuilder = new JcaContentSignerBuilder("SHA256withECDSA"); if (null != SECURITY_PROVIDER) { csBuilder.setProvider(SECURITY_PROVIDER); } ContentSigner signer = csBuilder.build(pair.getPrivate()); return certificationRequestToPEM(p10Builder.build(signer)); } catch (Exception e) { logger.error(e); throw new InvalidArgumentException(e); } }