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


C# X509Certificate.GetTbsCertificate方法代碼示例

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


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

示例1: GetSubjectX509Principal

		/// <summary>Return the subject of the given cert as an X509Principal.</summary>
		public static X509Name GetSubjectX509Principal(
			X509Certificate cert)
		{
			try
			{
				TbsCertificateStructure tbsCert = TbsCertificateStructure.GetInstance(
					Asn1Object.FromByteArray(cert.GetTbsCertificate()));

				return tbsCert.Subject;
			}
			catch (Exception e)
			{
				throw new CertificateEncodingException("Could not extract subject", e);
			}
		}
開發者ID:MBrekhof,項目名稱:pleiobox-clients,代碼行數:16,代碼來源:PrincipalUtil.cs

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

示例3: GetSubjectFields

 /**
 * Get the subject fields from an X509 Certificate
 * @param cert an X509Certificate
 * @return an X509Name
 */
 public static X509Name GetSubjectFields(X509Certificate cert) {
     return new X509Name((Asn1Sequence)GetSubject(cert.GetTbsCertificate()));
 }
開發者ID:nicecai,項目名稱:iTextSharp-4.1.6,代碼行數:8,代碼來源:PdfPKCS7.cs

示例4: ComputeRecipientInfo

 private KeyTransRecipientInfo ComputeRecipientInfo(X509Certificate x509certificate, byte[] abyte0) {
     Asn1InputStream asn1inputstream = 
         new Asn1InputStream(new MemoryStream(x509certificate.GetTbsCertificate()));
     TbsCertificateStructure tbscertificatestructure = 
         TbsCertificateStructure.GetInstance(asn1inputstream.ReadObject());
     AlgorithmIdentifier algorithmidentifier = tbscertificatestructure.SubjectPublicKeyInfo.AlgorithmID;
     Org.BouncyCastle.Asn1.Cms.IssuerAndSerialNumber issuerandserialnumber = 
         new Org.BouncyCastle.Asn1.Cms.IssuerAndSerialNumber(
             tbscertificatestructure.Issuer, 
             tbscertificatestructure.SerialNumber.Value);
     IBufferedCipher cipher = CipherUtilities.GetCipher(algorithmidentifier.ObjectID);
     cipher.Init(true, x509certificate.GetPublicKey());
     byte[] outp = new byte[10000];
     int len = cipher.DoFinal(abyte0, outp, 0);
     byte[] abyte1 = new byte[len];
     System.Array.Copy(outp, 0, abyte1, 0, len);
     DerOctetString deroctetstring = new DerOctetString(abyte1);
     RecipientIdentifier recipId = new RecipientIdentifier(issuerandserialnumber);
     return new KeyTransRecipientInfo( recipId, algorithmidentifier, deroctetstring);
 }        
開發者ID:jagruti23,項目名稱:itextsharp,代碼行數:20,代碼來源:PdfPublicKeySecurityHandler.cs

示例5: GetTbsCertificateStructure

		internal static TbsCertificateStructure GetTbsCertificateStructure(X509Certificate cert)
		{
			return TbsCertificateStructure.GetInstance(Asn1Object.FromByteArray(cert.GetTbsCertificate()));
		}
開發者ID:MBrekhof,項目名稱:pleiobox-clients,代碼行數:4,代碼來源:CMSUtils.cs

示例6: RecipientInf

			internal RecipientInf(
				X509Certificate cert)
			{
				this.cert = cert;
				this.pubKey = cert.GetPublicKey();

				try
				{
					TbsCertificateStructure tbs = TbsCertificateStructure.GetInstance(
						Asn1Object.FromByteArray(cert.GetTbsCertificate()));

					keyEncAlg = tbs.SubjectPublicKeyInfo.AlgorithmID;
				}
//				catch (IOException e)
				catch (Exception)
				{
					throw new ArgumentException("can't extract key algorithm from this cert");
				}
//				catch (CertificateEncodingException)
//				{
//					throw new ArgumentException("can't extract tbs structure from this cert");
//				}
			}
開發者ID:pusp,項目名稱:o2platform,代碼行數:23,代碼來源:CMSEnvelopedGenerator.cs


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