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


C# X509Certificate.GetExtensionValue方法代碼示例

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


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

示例1: ValidateCertificate

		/**
		 * Validate the passed in certificate as being of the correct type to be used
		 * for time stamping. To be valid it must have an ExtendedKeyUsage extension
		 * which has a key purpose identifier of id-kp-timeStamping.
		 *
		 * @param cert the certificate of interest.
		 * @throws TspValidationException if the certicate fails on one of the check points.
		 */
		public static void ValidateCertificate(
			X509Certificate cert)
		{
			if (cert.Version != 3)
				throw new ArgumentException("Certificate must have an ExtendedKeyUsage extension.");

			Asn1OctetString ext = cert.GetExtensionValue(X509Extensions.ExtendedKeyUsage);
			if (ext == null)
				throw new TspValidationException("Certificate must have an ExtendedKeyUsage extension.");

			if (!cert.GetCriticalExtensionOids().Contains(X509Extensions.ExtendedKeyUsage.Id))
				throw new TspValidationException("Certificate must have an ExtendedKeyUsage extension marked as critical.");

			try
			{
				ExtendedKeyUsage extKey = ExtendedKeyUsage.GetInstance(
					Asn1Object.FromByteArray(ext.GetOctets()));

				if (!extKey.HasKeyPurposeId(KeyPurposeID.IdKPTimeStamping) || extKey.Count != 1)
					throw new TspValidationException("ExtendedKeyUsage not solely time stamping.");
			}
			catch (IOException)
			{
				throw new TspValidationException("cannot process ExtendedKeyUsage extension");
			}
		}
開發者ID:pusp,項目名稱:o2platform,代碼行數:34,代碼來源:TSPUtil.cs

示例2: GetExtensionValue

        protected static Asn1Object GetExtensionValue(X509Certificate cert,
            string oid)
        {
            if (cert == null)
            {
                return null;
            }

            byte[] bytes = cert.GetExtensionValue(new DerObjectIdentifier(oid)).GetOctets();

            if (bytes == null)
            {
                return null;
            }

            Asn1InputStream aIn = new Asn1InputStream(bytes);

            return aIn.ReadObject();
        }
開發者ID:reisjr,項目名稱:BouncyCastleExamples,代碼行數:19,代碼來源:CertificateUtils.cs

示例3: GetExtensionValue

 private static Asn1Object GetExtensionValue(X509Certificate cert, String oid) {
     byte[] bytes = cert.GetExtensionValue(new DerObjectIdentifier(oid)).GetDerEncoded();
     if (bytes == null) {
         return null;
     }
     Asn1InputStream aIn = new Asn1InputStream(new MemoryStream(bytes));
     Asn1OctetString octs = (Asn1OctetString) aIn.ReadObject();
     aIn = new Asn1InputStream(new MemoryStream(octs.GetOctets()));
     return aIn.ReadObject();
 }
開發者ID:nicecai,項目名稱:iTextSharp-4.1.6,代碼行數:10,代碼來源:PdfPKCS7.cs

示例4: GetTSAURL

        // Time Stamp Authority

        /**
         * Gets the URL of the TSA if it's available on the certificate
         * @param certificate   a certificate
         * @return  a TSA URL
         * @throws IOException
         */
        public static String GetTSAURL(X509Certificate certificate) {
            Asn1OctetString octetString = certificate.GetExtensionValue(SecurityIDs.ID_TSA);
            if (octetString == null)
                return null;
            byte[] der = octetString.GetOctets();
            if (der == null)
                return null;
            Asn1Object asn1obj;
            try {
                asn1obj = Asn1Object.FromByteArray(der);
                if (asn1obj is DerOctetString) {
                    DerOctetString octets = (DerOctetString) asn1obj;
                    asn1obj = Asn1Object.FromByteArray(octets.GetOctets());
                }
                Asn1Sequence asn1seq = Asn1Sequence.GetInstance(asn1obj);
                return GetStringFromGeneralName(asn1seq[1].ToAsn1Object());
            } catch (IOException) {
                return null;
            }
        }
開發者ID:joshaxey,項目名稱:Simple-PDFMerge,代碼行數:28,代碼來源:CertificateUtil.cs

示例5: CopyAndAddExtension

		/**
		 * add a given extension field for the standard extensions tag (tag 3)
		 * copying the extension value from another certificate.
		 * @throws CertificateParsingException if the extension cannot be extracted.
		 */
		public void CopyAndAddExtension(
			DerObjectIdentifier	oid,
			bool				critical,
			X509Certificate		cert)
		{
			Asn1OctetString extValue = cert.GetExtensionValue(oid);

			if (extValue == null)
			{
				throw new CertificateParsingException("extension " + oid + " not present");
			}

			try
			{
				Asn1Encodable value = X509ExtensionUtilities.FromExtensionValue(extValue);

				this.AddExtension(oid, critical, value);
			}
			catch (Exception e)
			{
				throw new CertificateParsingException(e.Message, e);
			}
		}
開發者ID:KimikoMuffin,項目名稱:bc-csharp,代碼行數:28,代碼來源:X509V3CertificateGenerator.cs

示例6: ObtenerValorDeExtension

        protected static Asn1Object ObtenerValorDeExtension(X509Certificate in_Certificado,
                string oid)
        {
            if (in_Certificado == null)
            {
                return null;
            }

            byte[] bytes = in_Certificado.GetExtensionValue(new DerObjectIdentifier(oid)).GetOctets();

            if (bytes == null)
            {
                return null;
            }

            Asn1InputStream aIn = new Asn1InputStream(bytes);

            return aIn.ReadObject();
        }
開發者ID:maugsan,項目名稱:dcfd-mw-applet,代碼行數:19,代碼來源:OcspClient.cs

示例7: Init

		private void Init()
		{
			try
			{
				trustedCert = certParser.ReadCertificate(Base64.Decode(Trust_Anchor_CP_01_01_crt));
				trustedCRL = crlParser.ReadCrl(Base64.Decode(Trust_Anchor_CRL_CP_01_01_crl));
				trustedSet = new HashSet();

				byte[] _ncBytes = null;
				Asn1OctetString _oct = trustedCert.GetExtensionValue(X509Extensions.NameConstraints);
				if (_oct != null)
				{
					_ncBytes = _oct.GetOctets();
				}

				trustedSet.Add(new TrustAnchor(trustedCert, _ncBytes));
				testCount = 0;
				testFail = new ArrayList();
				resultBuf = new StringBuilder("\n");
			}
			catch (Exception ex)
			{
				throw new Exception(ex.Message);
			}
		}
開發者ID:KimikoMuffin,項目名稱:bc-csharp,代碼行數:25,代碼來源:NistCertPathTest.cs

示例8: GetCertificateInfo

        public static CertificateInfo GetCertificateInfo(byte[] certificate, TCertificateFormat certificateFormat)
        {
            CertificateInfo result = null;
            X509CertificateStructure cert = null;
            switch (certificateFormat)
            {
                case TCertificateFormat.NotSet:
                    break;
                case TCertificateFormat.PEM:
                    Org.BouncyCastle.Utilities.IO.Pem.PemReader reader = new Org.BouncyCastle.Utilities.IO.Pem.PemReader(new StreamReader(new MemoryStream(certificate)));
                    Org.BouncyCastle.Utilities.IO.Pem.PemObject pem = reader.ReadPemObject();
                    while (pem != null)
                    {
                        if (pem.Type.EndsWith("CERTIFICATE"))
                        {
                            cert = X509CertificateStructure.GetInstance(pem.Content);
                        }
                        else if (pem.Type.EndsWith("PRIVATE KEY"))
                        {
                            if (result == null)
                                result = new CertificateInfo();

                            result.PrivateKey = GetPrivateKeyFromPEM(pem);
                        }
                        pem = reader.ReadPemObject();
                    }
                    break;
                case TCertificateFormat.PFX:
                    break;
                case TCertificateFormat.CER:
                    cert = X509CertificateStructure.GetInstance(certificate);
                    break;
                default:
                    break;
            }
            if (cert != null)
            {
                if (result == null)
                    result = new CertificateInfo();
                result.Subject = new CertificateSubject(cert);
                X509Certificate certX509 = new X509Certificate(cert);
                Asn1OctetString subjectKeyID = certX509.GetExtensionValue(X509Extensions.SubjectKeyIdentifier);
                if (subjectKeyID != null)
                {
                    byte[] encodeKeyID = subjectKeyID.GetOctets();
                    byte[] keyID = new byte[encodeKeyID[1]];
                    Buffer.BlockCopy(encodeKeyID, 2, keyID, 0, encodeKeyID[1]);
                    result.SubjectKeyID = keyID;
                }
            }
            return result;
        }              
開發者ID:CreatorDev,項目名稱:DTLS.Net,代碼行數:52,代碼來源:Certificates.cs


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