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


C# X509Certificate.GetPublicKey方法代碼示例

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


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

示例1: IsSignedBy

		public virtual bool IsSignedBy(X509Certificate potentialIssuer)
		{
			try
			{
				GetCertificate().Verify(potentialIssuer.GetPublicKey());
				return true;
			}
			catch (InvalidKeyException)
			{
				return false;
			}
			catch (CertificateException)
			{
				return false;
			}
			catch (NoSuchAlgorithmException)
			{
				return false;
			}
			/*catch (NoSuchProviderException e)
			{
				throw new RuntimeException(e);
			}*/
			catch (SignatureException)
			{
				return false;
			}
		}
開發者ID:Gianluigi,項目名稱:dssnet,代碼行數:28,代碼來源:CertificateToken.cs

示例2: SecureMimeDigitalCertificate

        internal SecureMimeDigitalCertificate(X509Certificate certificate)
        {
            Certificate = certificate;

            var pubkey = certificate.GetPublicKey ();
            if (pubkey is DsaKeyParameters)
                PublicKeyAlgorithm = PublicKeyAlgorithm.Dsa;
            else if (pubkey is RsaKeyParameters)
                PublicKeyAlgorithm = PublicKeyAlgorithm.RsaGeneral;
            else if (pubkey is ElGamalKeyParameters)
                PublicKeyAlgorithm = PublicKeyAlgorithm.ElGamalGeneral;
            else if (pubkey is ECKeyParameters)
                PublicKeyAlgorithm = PublicKeyAlgorithm.EllipticCurve;
            else if (pubkey is DHKeyParameters)
                PublicKeyAlgorithm = PublicKeyAlgorithm.DiffieHellman;

            var encoded = certificate.GetEncoded ();
            var fingerprint = new StringBuilder ();
            var sha1 = new Sha1Digest ();
            var data = new byte[20];

            sha1.BlockUpdate (encoded, 0, encoded.Length);
            sha1.DoFinal (data, 0);

            for (int i = 0; i < data.Length; i++)
                fingerprint.Append (data[i].ToString ("X2"));

            Fingerprint = fingerprint.ToString ();
        }
開發者ID:princeoffoods,項目名稱:MimeKit,代碼行數:29,代碼來源:SecureMimeDigitalCertificate.cs

示例3: IsSignedBy

		public virtual bool IsSignedBy(X509Certificate potentialIssuer)
		{
			try
			{
				//return ocspResp.Verify(potentialIssuer.GetPublicKey(), "BC");
                return ocspResp.Verify(potentialIssuer.GetPublicKey());
			}
			/*catch (NoSuchProviderException e)
			{
				throw new RuntimeException(e);
			}*/
			catch (OcspException)
			{
				return false;
			}
		}
開發者ID:Gianluigi,項目名稱:dssnet,代碼行數:16,代碼來源:OCSPRespToken.cs

示例4: SecureMimeDigitalCertificate

		internal SecureMimeDigitalCertificate (X509Certificate certificate)
		{
			Certificate = certificate;

			var pubkey = certificate.GetPublicKey ();
			if (pubkey is DsaKeyParameters)
				PublicKeyAlgorithm = PublicKeyAlgorithm.Dsa;
			else if (pubkey is RsaKeyParameters)
				PublicKeyAlgorithm = PublicKeyAlgorithm.RsaGeneral;
			else if (pubkey is ElGamalKeyParameters)
				PublicKeyAlgorithm = PublicKeyAlgorithm.ElGamalGeneral;
			else if (pubkey is ECKeyParameters)
				PublicKeyAlgorithm = PublicKeyAlgorithm.EllipticCurve;
			else if (pubkey is DHKeyParameters)
				PublicKeyAlgorithm = PublicKeyAlgorithm.DiffieHellman;

			Fingerprint = certificate.GetFingerprint ();
		}
開發者ID:dcga,項目名稱:MimeKit,代碼行數:18,代碼來源:SecureMimeDigitalCertificate.cs

示例5: IsSignedBy

        public static bool IsSignedBy(this X509Certificate thisCertificate, X509Certificate signerCertificate)
        {
            X509Certificate2 c = new X509Certificate2(thisCertificate.GetTbsCertificate());
            X509Certificate2 i = new X509Certificate2(signerCertificate.GetTbsCertificate());
            X509Certificate2 c2 = new X509Certificate2(@"c:\temp\der.cer");
            X509Certificate2 i2 = new X509Certificate2(@"c:\temp\cader.cer");
            /*byte[] pvSubject = thisCertificate.GetTbsCertificate();
            byte[] pvIssuer = signerCertificate.GetTbsCertificate();
            */
            System.Text.Encoding.ASCII.GetString(c.RawData);
            IntPtr pvSubject = c.Handle;
            IntPtr pvIssuer = i.Handle;
            int res = SspiProvider.CryptVerifyCertificateSignatureEx(IntPtr.Zero, X509_ASN_ENCODING,
                                                           CRYPT_VERIFY_CERT_SIGN_SUBJECT_CERT, pvSubject,
                                                           CRYPT_VERIFY_CERT_SIGN_ISSUER_CERT, pvIssuer, 0,
                                                           IntPtr.Zero);
            Marshal.GetLastWin32Error();
            CmsSigner signer = new CmsSigner(i);
            SignedCms signedMessage = new SignedCms();
            // deserialize PKCS #7 byte array

            signedMessage.Decode(thisCertificate.GetTbsCertificate());
            Log.Write("Veryfy old");
            Log.Write("EndVeryfy old");
            Log.Write("Get signer's public key");
            var publicKey = signerCertificate.GetPublicKey();
            Log.Write("Got signer's public key");
            try
            {
                Log.Write("Veryfy signature");
                //TODO: log errors
                thisCertificate.Verify(publicKey);
                Log.Write("Verified");
            }
            catch (CertificateException)
            {
                return false;
            }
            catch (InvalidKeyException)
            {
                return false;
            }
            return true;
        }
開發者ID:demonix,項目名稱:CertVerifier,代碼行數:44,代碼來源:X509CertificateExtensions.cs

示例6: CertificateID

        /**
         * create from an issuer certificate and the serial number of the
         * certificate it signed.
         * @exception OcspException if any problems occur creating the id fields.
         */
        public CertificateID(
			string			hashAlgorithm,
			X509Certificate	issuerCert,
			BigInteger		number)
        {
            try
            {
                IDigest digest = DigestUtilities.GetDigest(hashAlgorithm);
                AlgorithmIdentifier hashAlg = new AlgorithmIdentifier(
                    new DerObjectIdentifier(hashAlgorithm), DerNull.Instance);

                X509Name issuerName = PrincipalUtilities.GetSubjectX509Principal(issuerCert);

                byte[] encodedIssuerName = issuerName.GetEncoded();
                digest.BlockUpdate(encodedIssuerName, 0, encodedIssuerName.Length);

                byte[] hash = DigestUtilities.DoFinal(digest);

                Asn1OctetString issuerNameHash = new DerOctetString(hash);
                AsymmetricKeyParameter issuerKey = issuerCert.GetPublicKey();

                SubjectPublicKeyInfo info = SubjectPublicKeyInfoFactory.CreateSubjectPublicKeyInfo(issuerKey);

                byte[] encodedPublicKey = info.PublicKeyData.GetBytes();
                digest.BlockUpdate(encodedPublicKey, 0, encodedPublicKey.Length);

                hash = DigestUtilities.DoFinal(digest);

                Asn1OctetString issuerKeyHash = new DerOctetString(hash);

                DerInteger serialNumber = new DerInteger(number);

                this.id = new CertID(hashAlg, issuerNameHash, issuerKeyHash, serialNumber);
            }
            catch (Exception e)
            {
                throw new OcspException("problem creating ID: " + e, e);
            }
        }
開發者ID:Noyabronok,項目名稱:itextsharpml,代碼行數:44,代碼來源:CertificateID.cs

示例7: VerifySignature

        public bool VerifySignature(X509Certificate attestationCertificate, byte[] signedBytes, byte[] signature)
        {
            if (attestationCertificate == null)
            {
                throw new ArgumentNullException(nameof(attestationCertificate));
            }
            if (signedBytes == null)
            {
                throw new ArgumentNullException(nameof(signedBytes));
            }
            if (signature == null)
            {
                throw new ArgumentNullException(nameof(signature));
            }

            var publicKey = attestationCertificate.GetPublicKey() as ECPublicKeyParameters;
            if (publicKey == null)
            {
                throw new U2FException("The certificate publickey isn't an Elliptic curve");
            }

            return VerifySignature(publicKey, signedBytes, signature);
        }
開發者ID:vbfox,項目名稱:U2FExperiments,代碼行數:23,代碼來源:BouncyCastleServerCrypto.cs

示例8: ValidateResponse

 private void ValidateResponse(BasicOcspResp or, X509Certificate issuerCert)
 {
     ValidateResponseSignature(or, issuerCert.GetPublicKey());
     ValidateSignerAuthorization(issuerCert, or.GetCerts()[0]);
 }
開發者ID:reisjr,項目名稱:BouncyCastleExamples,代碼行數:5,代碼來源:OcspClient.cs

示例9: VerifySignature

        /// <summary>
        /// Verify signature
        /// </summary>
        /// <returns>Boolean indicating success</returns>
        public bool VerifySignature(byte[] data, byte[] expectedSignature, X509Certificate cert)
        {
            /* Init alg */
            ISigner signer = SignerUtilities.GetSigner("SHA256withRSA");

            /* Populate key */
            signer.Init(false, cert.GetPublicKey());

            /* Calculate the signature and see if it matches */
            signer.BlockUpdate(data, 0, data.Length);
            return signer.VerifySignature(expectedSignature);
        }
開發者ID:ralphw1,項目名稱:limelight-wp,代碼行數:16,代碼來源:WPCryptoProvider.cs

示例10: CreateCertID

        private static CertID CreateCertID(
			AlgorithmIdentifier	hashAlg,
			X509Certificate		issuerCert,
			DerInteger			serialNumber)
		{
			try
			{
				String hashAlgorithm = hashAlg.ObjectID.Id;

				X509Name issuerName = PrincipalUtilities.GetSubjectX509Principal(issuerCert);
				byte[] issuerNameHash = DigestUtilities.CalculateDigest(
					hashAlgorithm, issuerName.GetEncoded());

				AsymmetricKeyParameter issuerKey = issuerCert.GetPublicKey();
				SubjectPublicKeyInfo info = SubjectPublicKeyInfoFactory.CreateSubjectPublicKeyInfo(issuerKey);
				byte[] issuerKeyHash = DigestUtilities.CalculateDigest(
					hashAlgorithm, info.PublicKeyData.GetBytes());

				return new CertID(hashAlg, new DerOctetString(issuerNameHash),
					new DerOctetString(issuerKeyHash), serialNumber);
			}
			catch (Exception e)
			{
				throw new OcspException("problem creating ID: " + e, e);
			}
		}
開發者ID:htlp,項目名稱:itextsharp,代碼行數:26,代碼來源:CertificateID.cs

示例11: 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

示例12: ValidateResponse

 private void ValidateResponse(BasicOcspResp in_OcspResp, X509Certificate in_CertificadoEmisor)
 {
     ValidarResponseSignature(in_OcspResp, in_CertificadoEmisor.GetPublicKey());
     ValidarSignerAuthorization(in_CertificadoEmisor, in_OcspResp.GetCerts()[0]);
 }
開發者ID:maugsan,項目名稱:dcfd-mw-applet,代碼行數:5,代碼來源:OcspClient.cs

示例13: IsSelfSigned

 private static bool IsSelfSigned(X509Certificate certificate)
 {
     if (!certificate.SubjectDN.Equivalent(certificate.IssuerDN))
         return false;
     try
     {
         certificate.Verify(certificate.GetPublicKey());
         return true;
     }
     catch (SignatureException)
     {
         return false;
     }
     catch (InvalidKeyException)
     {
         return false;
     }
 }
開發者ID:dataline-gmbh,項目名稱:Itsg.Ostc,代碼行數:18,代碼來源:OstcCertificateCollectionStore.cs

示例14: VerifySigner

		private void VerifySigner(SignerInformation signer, X509Certificate cert)
		{
			if (cert.GetPublicKey() is DsaPublicKeyParameters)
			{
				DsaPublicKeyParameters key = (DsaPublicKeyParameters)cert.GetPublicKey();

				if (key.Parameters == null)
				{
					Assert.IsTrue(signer.Verify(GetInheritedKey(key)));
				}
				else
				{
					Assert.IsTrue(signer.Verify(cert));
				}
			}
			else
			{
				Assert.IsTrue(signer.Verify(cert));
			}
		}
開發者ID:KimikoMuffin,項目名稱:bc-csharp,代碼行數:20,代碼來源:Rfc4134Test.cs

示例15: IsRequestSignatureValid

        private bool IsRequestSignatureValid(X509Certificate cert, string signature, HttpRequestBase request)
        {
            byte[] requestBytes;
            using (MemoryStream mem = new MemoryStream())
            {
                request.InputStream.CopyTo(mem);
                request.InputStream.Position = 0;
                requestBytes = mem.ToArray();
            }

            byte[] signatureBytes = null;
            try
            {
                signatureBytes = Convert.FromBase64String(signature);
            }
            catch (FormatException)
            {
                return false;
            }

            var publicKey = (RsaKeyParameters)cert.GetPublicKey();
            var signer = SignerUtilities.GetSigner("SHA1withRSA");
            signer.Init(false, publicKey);
            signer.BlockUpdate(requestBytes, 0, requestBytes.Length);

            return signer.VerifySignature(signatureBytes);
        }
開發者ID:RossLieberman,項目名稱:alexitech,代碼行數:27,代碼來源:ValidatingController.cs


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