Org.BouncyCastle.X509.X509Certificate.IsValid C# (CSharp) Method

IsValid() public method

Return true if the nominated time is within the start and end times nominated on the certificate.
public IsValid ( DateTime time ) : bool
time DateTime The time to test validity against.
return bool
        public virtual bool IsValid(
            DateTime time)
        {
            return time.CompareTo(NotBefore) >= 0 && time.CompareTo(NotAfter) <= 0;
        }

Usage Example

Example #1
0
 /**
  * Verifies a single certificate.
  * @param cert the certificate to verify
  * @param crls the certificate revocation list or <CODE>null</CODE>
  * @param calendar the date or <CODE>null</CODE> for the current date
  * @return a <CODE>String</CODE> with the error description or <CODE>null</CODE>
  * if no error
  */
 public static String VerifyCertificate(X509Certificate cert, ICollection<X509Crl> crls, DateTime calendar) {
     try {
         if (!cert.IsValid(calendar))
             return "The certificate has expired or is not yet valid";
         if (crls != null) {
             foreach (X509Crl crl in crls) {
                 if (crl.IsRevoked(cert))
                     return "Certificate revoked";
             }
         }
     }
     catch (Exception e) {
         return e.ToString();
     }
     return null;
 }
All Usage Examples Of Org.BouncyCastle.X509.X509Certificate::IsValid