use of org.bouncycastle.pkcs.PKCS10CertificationRequest in project android by nextcloud.
the class CsrHelper method generateCsrPemEncodedString.
/**
* Generate CSR with PEM encoding
*
* @param keyPair the KeyPair with private and public keys
* @param userId userId of CSR owner
* @return PEM encoded CSR string
* @throws IOException thrown if key cannot be created
* @throws OperatorCreationException thrown if contentSigner cannot be build
*/
public static String generateCsrPemEncodedString(KeyPair keyPair, String userId) throws IOException, OperatorCreationException {
PKCS10CertificationRequest csr = CsrHelper.generateCSR(keyPair, userId);
byte[] derCSR = csr.getEncoded();
return "-----BEGIN CERTIFICATE REQUEST-----\n" + android.util.Base64.encodeToString(derCSR, android.util.Base64.NO_WRAP) + "\n-----END CERTIFICATE REQUEST-----";
}
use of org.bouncycastle.pkcs.PKCS10CertificationRequest in project dcos-commons by mesosphere.
the class TLSArtifactsGenerator method generateCSR.
@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);
}
use of org.bouncycastle.pkcs.PKCS10CertificationRequest in project Spark by igniterealtime.
the class MutualAuthenticationSettingsPanel method createCertificateSignRequest.
private void createCertificateSignRequest() {
idControll.setUpData(commonNameField.getText(), organizationUnitField.getText(), organizationField.getText(), countryField.getText(), cityField.getText());
try {
KeyPair keyPair = idControll.createKeyPair();
PKCS10CertificationRequest request = idControll.createCSR(keyPair);
PemHelper.saveToPemFile(keyPair, IdentityController.KEY_FILE);
PemHelper.saveToPemFile(request, IdentityController.CSR_FILE);
JOptionPane.showMessageDialog(null, Res.getString("dialog.certificate.request.has.been.created") + IdentityController.SECURITY_DIRECTORY.toString());
} catch (OperatorCreationException | NoSuchAlgorithmException | IOException | NoSuchProviderException e1) {
Log.error("Couldn't create Certificate Signing Request", e1);
}
}
Aggregations