SignedCertificateGenerator { public X509Certificate getSelfSigned(final KeyPair keyPair, final CertificateGenerationParameters params) throws Exception { final SubjectKeyIdentifier keyIdentifier = getSubjectKeyIdentifierFromKeyInfo(keyPair.getPublic()); return getSignedByIssuer( null, keyPair.getPrivate(), params.getX500Principal(), keyIdentifier, keyPair, params ); } @Autowired  SignedCertificateGenerator(
    final CurrentTimeProvider timeProvider,
    final RandomSerialNumberGenerator serialNumberGenerator,
    final JcaContentSignerBuilder jcaContentSignerBuilder,
    final JcaX509CertificateConverter jcaX509CertificateConverter
  ); X509Certificate getSelfSigned(final KeyPair keyPair, final CertificateGenerationParameters params); X509Certificate getSignedByIssuer(
    final KeyPair keyPair,
    final CertificateGenerationParameters params,
    final X509Certificate caCertificate,
    final PrivateKey caPrivateKey);  }
@Test public void getSelfSigned_generatesACertificateWithTheRightValues() throws Exception { final X509Certificate generatedCertificate = subject.getSelfSigned(generatedCertificateKeyPair, certificateGenerationParameters); assertThat(generatedCertificate.getIssuerDN().getName(), containsString("CN=my cert name")); assertThat(generatedCertificate.getSubjectDN().toString(), containsString("CN=my cert name")); generatedCertificate.verify(generatedCertificateKeyPair.getPublic()); final byte[] authorityKeyIdDer = generatedCertificate.getExtensionValue(Extension.authorityKeyIdentifier.getId()); final AuthorityKeyIdentifier authorityKeyIdentifier = AuthorityKeyIdentifier.getInstance(parseExtensionValue(authorityKeyIdDer)); final byte[] authorityKeyId = authorityKeyIdentifier.getKeyIdentifier(); expectedSubjectKeyIdentifier = jcaX509ExtensionUtils.createSubjectKeyIdentifier(generatedCertificateKeyPair.getPublic()).getKeyIdentifier(); assertThat(authorityKeyId, equalTo(expectedSubjectKeyIdentifier)); assertThat(generatedCertificate.getSerialNumber(), equalTo(BigInteger.valueOf(1337))); }