Code example for X509Certificate

Methods: getNotAfter

0
        assertNotNull(certificate);
 
        // The "not-after" (a.k.a. expiration) date should be after "now" 
        Calendar c = Calendar.getInstance();
        c.setTimeInMillis(now);
        assertTrue(certificate.getNotAfter().compareTo(c.getTime()) > 0);
 
        // It should be valid after 1 year from now (adjust by a second since the 'now' time 
        // doesn't exactly match the creation time... 1 second should be enough.) 
        c.add(Calendar.DAY_OF_YEAR, 365);
        c.add(Calendar.SECOND, -1);
        assertTrue("1 year expiration failed",
                certificate.getNotAfter().compareTo(c.getTime()) > 0);
 
        // and 30 years from now 
        c.add(Calendar.DAY_OF_YEAR, 29 * 365);
        assertTrue("30 year expiration failed",
                certificate.getNotAfter().compareTo(c.getTime()) > 0);
 
        // however expiration date should be passed in 30 years + 1 hour 
        c.add(Calendar.HOUR, 1);
        assertFalse("30 year and 1 hour expiration failed",
                certificate.getNotAfter().compareTo(c.getTime()) > 0);
    } 
 
    private static class KeygenOutput implements IKeyGenOutput { 
        private String mOut = "";               //$NON-NLS-1$
        private String mErr = "";               //$NON-NLS-1$