X500Name entityName = new X500Name("CN=entity");
KeyPair entityPair = KeyPairGenerator.getInstance("RSA").genKeyPair();
SubjectPublicKeyInfo publicKeyInfo = SubjectPublicKeyInfo
.getInstance(entityPair.getPublic().getEncoded());
// Generate the certificate signing request
PKCS10CertificationRequestBuilder csrBuilder = new PKCS10CertificationRequestBuilder(
entityName, publicKeyInfo);
// SCEP servers usually require a challenge password
csrBuilder.addAttribute(
PKCSObjectIdentifiers.pkcs_9_at_challengePassword,
new DERPrintableString(new String("password".toCharArray())));
ContentSigner signer = signerBuilder.build(entityPair.getPrivate());
PKCS10CertificationRequest csr = csrBuilder.build(signer);
// Send the enrollment request
EnrollmentResponse response = client
.enrol(id, idPair.getPrivate(), csr);
if (response.isFailure()) {