Code example for X509Certificate

Methods: getNotAfter

0
 
	protected static X509Certificate createProxyCertificate(String provider, X509Certificate issuerCert,
		PrivateKey issuerKey, PublicKey publicKey, int lifetimeHours, int lifetimeMinutes, int lifetimeSeconds,
		int proxyType, X509ExtensionSet extSet, String signatureAlgorithm) throws GeneralSecurityException {
		Date d = getProxyValid(lifetimeHours, lifetimeMinutes, lifetimeSeconds);
		if (issuerCert.getNotAfter().before(d)) {
			throw new GeneralSecurityException("Cannot create a proxy that expires after issuing certificate.");
		} 
		int hoursToSeconds = lifetimeHours * 60 * 60;
		int minutesToSeconds = lifetimeMinutes * 60;
		int seconds = hoursToSeconds + minutesToSeconds + lifetimeSeconds;
		BouncyCastleCertProcessingFactory bc = BouncyCastleCertProcessingFactory.getDefault();
		return bc.createProxyCertificate(provider, issuerCert, issuerKey, publicKey, seconds, proxyType, extSet, null,
			signatureAlgorithm);
	} 
 
 
	public static Date getProxyValid(int lifetimeHours, int lifetimeMinutes, int lifetimeSeconds) {
		Calendar c = new GregorianCalendar();
		c.add(Calendar.HOUR_OF_DAY, lifetimeHours);