@Test public void testGenerateX509CertificateV1() throws NoSuchAlgorithmException, NoSuchProviderException, CertificateExpiredException, CertificateNotYetValidException, CertificateException, InvalidKeyException, SignatureException { final DistinguishedName issuer = issuer(); final X500Principal issuerPrincipal = issuer.toX500Principal(); final KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance(RSA.name(), BOUNCY_CASTLE); final KeyPair signingKeyPair = keyPairGenerator.generateKeyPair(); final KeyPair certKeyPair = keyPairGenerator.generateKeyPair(); final X509V1CertRequest request = new X509V1CertRequest( issuerPrincipal, BigInteger.ONE, Instant.now(), Instant.ofEpochMilli(System.currentTimeMillis() + (10 * 1000)), issuerPrincipal, certKeyPair.getPublic() ); log.info(String.format("request : %s", request)); final X509Certificate cert = certificateService.generateX509CertificateV1(request, signingKeyPair.getPrivate()); log.info(String.format("result.getSigAlgName() = %s, result.getVersion() = %s ", cert.getSigAlgName(), cert.getVersion())); assertThat(cert.getVersion(), is(1)); cert.checkValidity(); assertThat(Arrays.areEqual(issuerPrincipal.getEncoded(), cert.getIssuerX500Principal().getEncoded()), is(true)); cert.verify(signingKeyPair.getPublic()); }
@Override public X509Certificate generateX509CertificateV1(@NonNull final X509V1CertRequest request, @NonNull final PrivateKey privateKey) { final ContentSigner signer = contentSigner(privateKey); final X509v1CertificateBuilder certBuilder = request.x509v1CertificateBuilder(); final X509CertificateHolder certHolder = certBuilder.build(signer); return toX509Certificate(certHolder); }
CertificateServiceImpl implements CertificateService { @Override public X509Certificate generateX509CertificateV1(@NonNull final X509V1CertRequest request, @NonNull final PrivateKey privateKey) { final ContentSigner signer = contentSigner(privateKey); final X509v1CertificateBuilder certBuilder = request.x509v1CertificateBuilder(); final X509CertificateHolder certHolder = certBuilder.build(signer); return toX509Certificate(certHolder); } }
CertificateServiceImpl implements CertificateService { @Override public X509Certificate generateX509CertificateV1(@NonNull final X509V1CertRequest request, @NonNull final PrivateKey privateKey) { final ContentSigner signer = contentSigner(privateKey); final X509v1CertificateBuilder certBuilder = request.x509v1CertificateBuilder(); final X509CertificateHolder certHolder = certBuilder.build(signer); return toX509Certificate(certHolder); }  }
CertificateServiceImpl implements CertificateService { @Override public X509Certificate generateX509CertificateV1(@NonNull final X509V1CertRequest request, @NonNull final PrivateKey privateKey) { final ContentSigner signer = contentSigner(privateKey); final X509v1CertificateBuilder certBuilder = request.x509v1CertificateBuilder(); final X509CertificateHolder certHolder = certBuilder.build(signer); return toX509Certificate(certHolder); }  @Override X509Certificate generateX509CertificateV1(@NonNull final X509V1CertRequest request, @NonNull final PrivateKey privateKey); @Override X509Certificate generateX509CertificateV3(@NonNull final X509V3CertRequest request, @NonNull final PrivateKey privateKey); }
CertificateServiceImpl implements CertificateService { @Override public X509Certificate generateX509CertificateV1(@NonNull final X509V1CertRequest request, @NonNull final PrivateKey privateKey) { final ContentSigner signer = contentSigner(privateKey); final X509v1CertificateBuilder certBuilder = request.x509v1CertificateBuilder(); final X509CertificateHolder certHolder = certBuilder.build(signer); return toX509Certificate(certHolder); }  @Override X509Certificate generateX509CertificateV1(@NonNull final X509V1CertRequest request, @NonNull final PrivateKey privateKey); @Override X509Certificate generateX509CertificateV3(@NonNull final X509V3CertRequest request, @NonNull final PrivateKey privateKey);  }