core/src/main/java/org/keycloak/util/CertificateUtils.java
/**
     * Generate version 1 self signed {@link java.security.cert.X509Certificate}..
     *
     * @param caKeyPair the CA key pair
     * @param subject the subject name
     * 
     * @return the x509 certificate
     * 
     * @throws Exception the exception
     */
Generate version 1 self signed  java.security.cert.X509Certificate

@param caKeyPair the CA key pair
@param subject the subject name

@return the x509 certificate

@throws Exception the exception
Generate version 1 self signed java . security . cert . X509Certificate @param caKeyPair the CA key pair @param subject the subject name @return the x509 certificate @throws Exception the exception
public static X509Certificate generateV1SelfSignedCertificate(KeyPair caKeyPair, String subject) throws Exception {
        try {
            X500Name subjectDN = new X500Name("CN=" + subject);
            BigInteger serialNumber = BigInteger.valueOf(System.currentTimeMillis());
            Date validityStartDate = new Date(System.currentTimeMillis() - 100000);
            Calendar calendar = Calendar.getInstance();
            calendar.add(Calendar.YEAR, 10);
            Date validityEndDate = new Date(calendar.getTime().getTime());
            SubjectPublicKeyInfo subPubKeyInfo = SubjectPublicKeyInfo.getInstance(caKeyPair.getPublic().getEncoded());
            X509v1CertificateBuilder builder = new X509v1CertificateBuilder(subjectDN, serialNumber, validityStartDate,
                    validityEndDate, subjectDN, subPubKeyInfo);
            X509CertificateHolder holder = builder.build(createSigner(caKeyPair.getPrivate()));
            return new JcaX509CertificateConverter().getCertificate(holder);
        } catch (Exception e) {
            throw new RuntimeException("Error creating X509v1Certificate.", e);
        }
    }
public static X509Certificate generateV1SelfSignedCertificate ( KeyPair caKeyPair , String subject ) throws Exception { try { X500Name subjectDN = new X500Name ( "CN=" + subject ) ; BigInteger serialNumber = BigInteger . valueOf ( System . currentTimeMillis ( ) ) ; Date validityStartDate = new Date ( System . currentTimeMillis ( ) - 100000 ) ; Calendar calendar = Calendar . getInstance ( ) ; calendar . add ( Calendar . YEAR , 10 ) ; Date validityEndDate = new Date ( calendar . getTime ( ) . getTime ( ) ) ; SubjectPublicKeyInfo subPubKeyInfo = SubjectPublicKeyInfo . getInstance ( caKeyPair . getPublic ( ) . getEncoded ( ) ) ; X509v1CertificateBuilder builder = new X509v1CertificateBuilder ( subjectDN , serialNumber , validityStartDate , validityEndDate , subjectDN , subPubKeyInfo ) ; X509CertificateHolder holder = builder . build ( createSigner ( caKeyPair . getPrivate ( ) ) ) ; return new JcaX509CertificateConverter ( ) . getCertificate ( holder ) ; } catch ( Exception e ) { throw new RuntimeException ( "Error creating X509v1Certificate." , e ) ; } }
Generate version 1 self signed {@link java.security.cert.X509Certificate}..
Generate version 1 self signed { @link java . security . cert . X509Certificate } ..