當前位置: 首頁>>代碼示例>>C#>>正文


C# X509Certificate.CheckValidity方法代碼示例

本文整理匯總了C#中Org.BouncyCastle.X509.X509Certificate.CheckValidity方法的典型用法代碼示例。如果您正苦於以下問題:C# X509Certificate.CheckValidity方法的具體用法?C# X509Certificate.CheckValidity怎麽用?C# X509Certificate.CheckValidity使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Org.BouncyCastle.X509.X509Certificate的用法示例。


在下文中一共展示了X509Certificate.CheckValidity方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Verify

	    /**
	     * Checks the validity of the certificate, and calls the next
	     * verifier in the chain, if any.
	     * @param signCert	the certificate that needs to be checked
	     * @param issuerCert	its issuer
	     * @param signDate		the date the certificate needs to be valid
	     * @return a list of <code>VerificationOK</code> objects.
	     * The list will be empty if the certificate couldn't be verified.
	     * @throws GeneralSecurityException
	     * @throws IOException
	     */
	    virtual public List<VerificationOK> Verify(X509Certificate signCert, X509Certificate issuerCert, DateTime signDate) {
		    // Check if the certificate is valid on the signDate
		    //if (signDate != null)
			    signCert.CheckValidity(signDate);
		    // Check if the signature is valid
		    if (issuerCert != null) {
			    signCert.Verify(issuerCert.GetPublicKey());
		    }
		    // Also in case, the certificate is self-signed
		    else {
			    signCert.Verify(signCert.GetPublicKey());
		    }
		    List<VerificationOK> result = new List<VerificationOK>();
		    if (verifier != null)
			    result.AddRange(verifier.Verify(signCert, issuerCert, signDate));
		    return result;
	    }
開發者ID:joshaxey,項目名稱:Simple-PDFMerge,代碼行數:28,代碼來源:CertificateVerifier.cs

示例2: Validate

		/**
		 * Validate the time stamp token.
		 * <p>
		 * To be valid the token must be signed by the passed in certificate and
		 * the certificate must be the one referred to by the SigningCertificate
		 * attribute included in the hashed attributes of the token. The
		 * certificate must also have the ExtendedKeyUsageExtension with only
		 * KeyPurposeID.IdKPTimeStamping and have been valid at the time the
		 * timestamp was created.
		 * </p>
		 * <p>
		 * A successful call to validate means all the above are true.
		 * </p>
		 */
		public void Validate(
			X509Certificate cert)
		{
			try
			{
				byte[] hash = DigestUtilities.CalculateDigest(
					certID.GetHashAlgorithm(), cert.GetEncoded());

				if (!Arrays.ConstantTimeAreEqual(certID.GetCertHash(), hash))
				{
					throw new TspValidationException("certificate hash does not match certID hash.");
				}

				if (certID.IssuerSerial != null)
				{
					if (!certID.IssuerSerial.Serial.Value.Equals(cert.SerialNumber))
					{
						throw new TspValidationException("certificate serial number does not match certID for signature.");
					}

					GeneralName[] names = certID.IssuerSerial.Issuer.GetNames();
					X509Name principal = PrincipalUtilities.GetIssuerX509Principal(cert);
					bool found = false;

					for (int i = 0; i != names.Length; i++)
					{
						if (names[i].TagNo == 4
							&& X509Name.GetInstance(names[i].Name).Equivalent(principal))
						{
							found = true;
							break;
						}
					}

					if (!found)
					{
						throw new TspValidationException("certificate name does not match certID for signature. ");
					}
				}

				TspUtil.ValidateCertificate(cert);

				cert.CheckValidity(tstInfo.GenTime);

				if (!tsaSignerInfo.Verify(cert))
				{
					throw new TspValidationException("signature not created by certificate.");
				}
			}
			catch (CmsException e)
			{
				if (e.InnerException != null)
				{
					throw new TspException(e.Message, e.InnerException);
				}

				throw new TspException("CMS exception: " + e, e);
			}
			catch (CertificateEncodingException e)
			{
				throw new TspException("problem processing certificate: " + e, e);
			}
			catch (SecurityUtilityException e)
			{
				throw new TspException("cannot find algorithm: " + e.Message, e);
			}
		}
開發者ID:randombit,項目名稱:hacrypto,代碼行數:81,代碼來源:TimeStampToken.cs

示例3: EnsureCertificateValidity

 private void EnsureCertificateValidity(X509Certificate certificate)
 {
     certificate.CheckValidity(DateTime.UtcNow);
     certificate.Verify(_authorityKeyPair.Public);
 }
開發者ID:Richard-FF,項目名稱:wcf,代碼行數:5,代碼來源:CertificateGenerator.cs

示例4: CertIsValidNow

 /// <summary>
 /// Checks the certificate in this same date and time.
 /// </summary>
 /// <returns>
 /// <c>true</c>, if is valid now, <c>false</c> otherwise.
 /// </returns>
 /// <param name='BCCert'>
 /// BouncyCastle cert to check.
 /// </param>
 private static bool CertIsValidNow(X509Certificate BCCert)
 {
     try
     {
         BCCert.CheckValidity();
         return BCCert.IsValidNow;
     }catch(CertificateExpiredException ce){
         SystemLogger.Log (SystemLogger.Module.PLATFORM, "*************** Certificate Validation: Certificate has expired");
     }catch(CertificateNotYetValidException cex){
         SystemLogger.Log (SystemLogger.Module.PLATFORM, "*************** Certificate Validation: Certificate is not yet valid");
     }
     return false;
 }
開發者ID:ik3210,項目名稱:appverse-mobile,代碼行數:22,代碼來源:SecurityUtils.cs

示例5: Verify

		/**
		* verify that the given certificate successfully handles and confirms
		* the signature associated with this signer and, if a signingTime
		* attribute is available, that the certificate was valid at the time the
		* signature was generated.
		*/
		public bool Verify(
			X509Certificate cert)
		{
			Asn1.Cms.AttributeTable attr = this.SignedAttributes;

			if (attr != null)
			{
				Asn1EncodableVector v = attr.GetAll(CmsAttributes.SigningTime);
				switch (v.Count)
				{
					case 0:
						break;
					case 1:
					{
						Asn1.Cms.Attribute t = (Asn1.Cms.Attribute) v[0];
						Debug.Assert(t != null);

						Asn1Set attrValues = t.AttrValues;
						if (attrValues.Count != 1)
							throw new CmsException("A signing-time attribute MUST have a single attribute value");

						Asn1.Cms.Time time = Asn1.Cms.Time.GetInstance(attrValues[0].ToAsn1Object());

						cert.CheckValidity(time.Date);
						break;
					}
					default:
						throw new CmsException("The SignedAttributes in a signerInfo MUST NOT include multiple instances of the signing-time attribute");
				}
			}

			return DoVerify(cert.GetPublicKey(), attr);
		}
開發者ID:nicecai,項目名稱:iTextSharp-4.1.6,代碼行數:39,代碼來源:SignerInformation.cs

示例6: Verify

        /**
        * verify that the given certificate succesfully handles and confirms
        * the signature associated with this signer and, if a signingTime
        * attribute is available, that the certificate was valid at the time the
        * signature was generated.
        */
        public bool Verify(
			X509Certificate cert)
        {
            Asn1.Cms.AttributeTable attr = this.SignedAttributes;

            if (attr != null)
            {
                Asn1.Cms.Attribute t = attr[CmsAttributes.SigningTime];

                if (t != null)
                {
                    Asn1.Cms.Time time = Asn1.Cms.Time.GetInstance(
                        t.AttrValues[0].ToAsn1Object());

                    cert.CheckValidity(time.Date);
                }
            }

            return DoVerify(cert.GetPublicKey(), attr);
        }
開發者ID:hjgode,項目名稱:iTextSharpCF,代碼行數:26,代碼來源:SignerInformation.cs

示例7: ShowCertificateInfo

 public static void ShowCertificateInfo(X509Certificate cert, DateTime signDate)
 {
     Console.WriteLine("Issuer: " + cert.IssuerDN);
     Console.WriteLine("Subject: " + cert.SubjectDN);
     Console.WriteLine("Valido dede: " + cert.NotBefore.ToString("yyyy-MM-dd HH:mm:ss.ff"));
     Console.WriteLine("Valido hasta: " + cert.NotAfter.ToString("yyyy-MM-dd HH:mm:ss.ff"));
     try
     {
         cert.CheckValidity(signDate);
         Console.WriteLine("El certificado era valido al momento de la firma.");
     }
     catch (CertificateExpiredException e)
     {
         Console.WriteLine("El certificado estaba expirado al momento de la firma. " + e.ToString());
     }
     catch (CertificateNotYetValidException e)
     {
         Console.WriteLine("El certificado no era válido aún al momento de la firma. " + e.ToString());
     }
     try
     {
         cert.CheckValidity();
         Console.WriteLine("El certificado sigue siendo válido.");
     }
     catch (CertificateExpiredException e)
     {
         Console.WriteLine("El certificado ha expirado. " + e.ToString());
     }
     catch (CertificateNotYetValidException e)
     {
         Console.WriteLine("El certificado no es válido aún. " + e.ToString());
     }
 }
開發者ID:bochi2511,項目名稱:SignDoc,代碼行數:33,代碼來源:PdfSignature.cs

示例8: GetCertificateInfo

        private static MessageReport.Cert GetCertificateInfo(X509Certificate cert, DateTime signDate)
        {
            MessageReport.Cert c = new MessageReport.Cert();

            c.isHardCertificate = isHardCertificatePolicyOidt(cert);

            c.issuer = cert.IssuerDN.ToString();
            c.subject = cert.SubjectDN.ToString();
            c.validFrom = cert.NotBefore.ToString("yyyy-MM-dd HH:mm:ss.ff");
            c.validTo = cert.NotAfter.ToString("yyyy-MM-dd HH:mm:ss.ff");

            try
            {
                cert.CheckValidity(signDate);
                c.statusDaySigning = "Έγκυρο κατά το χρόνο υπογραφής";

            }
            catch (CertificateExpiredException e)
            {
                c.statusDaySigning = "Έίχε λήξει κατά το χρόνο υπογραφής.";
            }
            catch (CertificateNotYetValidException e)
            {
                c.statusDaySigning = "Δεν ήταν έγκυρο κατά το χρόνο υπογραφής";
            }

            try
            {
                cert.CheckValidity();
                c.statusToday = "Έγκυρο";
            }
            catch (CertificateExpiredException e)
            {
                c.statusToday = "Έχει λήξει";
            }
            catch (CertificateNotYetValidException e)
            {
                c.statusToday = "Μη έγκυρο";
            }

            return c;
        }
開發者ID:ellak-monades-aristeias,項目名稱:DigitalSIgnatureCheckGR,代碼行數:42,代碼來源:SignatureValidator.cs


注:本文中的Org.BouncyCastle.X509.X509Certificate.CheckValidity方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。