久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

<legend id='LtFmh'><style id='LtFmh'><dir id='LtFmh'><q id='LtFmh'></q></dir></style></legend>
  • <tfoot id='LtFmh'></tfoot>

      1. <i id='LtFmh'><tr id='LtFmh'><dt id='LtFmh'><q id='LtFmh'><span id='LtFmh'><b id='LtFmh'><form id='LtFmh'><ins id='LtFmh'></ins><ul id='LtFmh'></ul><sub id='LtFmh'></sub></form><legend id='LtFmh'></legend><bdo id='LtFmh'><pre id='LtFmh'><center id='LtFmh'></center></pre></bdo></b><th id='LtFmh'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='LtFmh'><tfoot id='LtFmh'></tfoot><dl id='LtFmh'><fieldset id='LtFmh'></fieldset></dl></div>
      2. <small id='LtFmh'></small><noframes id='LtFmh'>

          <bdo id='LtFmh'></bdo><ul id='LtFmh'></ul>

        C# 如何驗證 Root-CA-Cert 證書 (x509) 鏈?

        C# How can I validate a Root-CA-Cert certificate (x509) chain?(C# 如何驗證 Root-CA-Cert 證書 (x509) 鏈?)

        <i id='j68K9'><tr id='j68K9'><dt id='j68K9'><q id='j68K9'><span id='j68K9'><b id='j68K9'><form id='j68K9'><ins id='j68K9'></ins><ul id='j68K9'></ul><sub id='j68K9'></sub></form><legend id='j68K9'></legend><bdo id='j68K9'><pre id='j68K9'><center id='j68K9'></center></pre></bdo></b><th id='j68K9'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='j68K9'><tfoot id='j68K9'></tfoot><dl id='j68K9'><fieldset id='j68K9'></fieldset></dl></div>

        1. <small id='j68K9'></small><noframes id='j68K9'>

            <bdo id='j68K9'></bdo><ul id='j68K9'></ul>
                <tbody id='j68K9'></tbody>
                • <legend id='j68K9'><style id='j68K9'><dir id='j68K9'><q id='j68K9'></q></dir></style></legend>
                  <tfoot id='j68K9'></tfoot>
                  本文介紹了C# 如何驗證 Root-CA-Cert 證書 (x509) 鏈?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  限時送ChatGPT賬號..

                  假設我有三個證書(Base64 格式)

                  Let's say I have three certificates (in Base64 format)

                  Root
                   |
                   --- CA
                       |
                       --- Cert (client/signing/whatever)
                  

                  如何在 C# 中驗證證書和證書路徑/鏈?(所有這三個證書可能不在我的計算機證書存儲中)

                  How can I validate the certs and certificate path/chain in C#? (All those three certs may not be in my computer cert store)

                  編輯:BouncyCastle 具有驗證功能.但我盡量不使用任何第三方庫.

                  Edit: BouncyCastle has the function to verify. But I'm trying not to use any third-party library.

                      byte[] b1 = Convert.FromBase64String(x509Str1);
                      byte[] b2 = Convert.FromBase64String(x509Str2);
                      X509Certificate cer1 = 
                          new X509CertificateParser().ReadCertificate(b1);
                      X509Certificate cer2 =
                          new X509CertificateParser().ReadCertificate(b2);
                      cer1.Verify(cer2.GetPublicKey());
                  

                  如果 cer1 沒有被 cert2(CA 或 root)簽名,就會出現異常.這正是我想要的.

                  If the cer1 is not signed by cert2 (CA or root), there will be exception. This is exactly what I want.

                  推薦答案

                  X509Chain 類就是為此而設計的,您甚至可以自定義它如何執行鏈構建過程.

                  The X509Chain class was designed to do this, you can even customize how it performs the chain building process.

                  static bool VerifyCertificate(byte[] primaryCertificate, IEnumerable<byte[]> additionalCertificates)
                  {
                      var chain = new X509Chain();
                      foreach (var cert in additionalCertificates.Select(x => new X509Certificate2(x)))
                      {
                          chain.ChainPolicy.ExtraStore.Add(cert);
                      }
                  
                      // You can alter how the chain is built/validated.
                      chain.ChainPolicy.RevocationMode = X509RevocationMode.NoCheck;
                      chain.ChainPolicy.VerificationFlags = X509VerificationFlags.IgnoreWrongUsage;
                  
                      // Do the validation.
                      var primaryCert = new X509Certificate2(primaryCertificate);
                      return chain.Build(primaryCert);
                  }
                  

                  如果您需要,X509Chain 將包含有關 Build() == false 之后驗證失敗的附加信息.

                  The X509Chain will contain additional information about the validation failure after Build() == false if you need it.

                  這只會確保您的 CA 有效.如果要確保鏈相同,可以手動檢查指紋.可以使用下面的方法來保證認證鏈是正確的,它期望鏈的順序是:..., INTERMEDIATE2, INTERMEDIATE1 (Signer of INTERMEDIATE2), CA (Signer of INTERMEDIATE1)

                  This will merely ensure that your CA's are valid. If you want to ensure that the chain is identical you can check the thumbprints manually. You can use the following method to ensure that the certification chain is correct, it expects the chain in the order: ..., INTERMEDIATE2, INTERMEDIATE1 (Signer of INTERMEDIATE2), CA (Signer of INTERMEDIATE1)

                  static bool VerifyCertificate(byte[] primaryCertificate, IEnumerable<byte[]> additionalCertificates)
                  {
                      var chain = new X509Chain();
                      foreach (var cert in additionalCertificates.Select(x => new X509Certificate2(x)))
                      {
                          chain.ChainPolicy.ExtraStore.Add(cert);
                      }
                  
                      // You can alter how the chain is built/validated.
                      chain.ChainPolicy.RevocationMode = X509RevocationMode.NoCheck;
                      chain.ChainPolicy.VerificationFlags = X509VerificationFlags.IgnoreWrongUsage;
                  
                      // Do the preliminary validation.
                      var primaryCert = new X509Certificate2(primaryCertificate);
                      if (!chain.Build(primaryCert))
                          return false;
                  
                      // Make sure we have the same number of elements.
                      if (chain.ChainElements.Count != chain.ChainPolicy.ExtraStore.Count + 1)
                          return false;
                  
                      // Make sure all the thumbprints of the CAs match up.
                      // The first one should be 'primaryCert', leading up to the root CA.
                      for (var i = 1; i < chain.ChainElements.Count; i++)
                      {
                          if (chain.ChainElements[i].Certificate.Thumbprint != chain.ChainPolicy.ExtraStore[i - 1].Thumbprint)
                              return false;
                      }
                  
                      return true;
                  }
                  

                  我無法對此進行測試,因為我沒有完整的 CA 鏈,因此最好調試并逐步執行代碼.

                  這篇關于C# 如何驗證 Root-CA-Cert 證書 (x509) 鏈?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  What are good algorithms for vehicle license plate detection?(車牌檢測有哪些好的算法?)
                  onClick event for Image in Unity(Unity中圖像的onClick事件)
                  Running Total C#(運行總 C#)
                  Deleting a directory when clicked on a hyperlink with JAvascript.ASP.NET C#(單擊帶有 JAvascript.ASP.NET C# 的超鏈接時刪除目錄)
                  asp.net listview highlight row on click(asp.net listview 在單擊時突出顯示行)
                  Calling A Button OnClick from a function(從函數調用按鈕 OnClick)
                • <i id='NOuij'><tr id='NOuij'><dt id='NOuij'><q id='NOuij'><span id='NOuij'><b id='NOuij'><form id='NOuij'><ins id='NOuij'></ins><ul id='NOuij'></ul><sub id='NOuij'></sub></form><legend id='NOuij'></legend><bdo id='NOuij'><pre id='NOuij'><center id='NOuij'></center></pre></bdo></b><th id='NOuij'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='NOuij'><tfoot id='NOuij'></tfoot><dl id='NOuij'><fieldset id='NOuij'></fieldset></dl></div>
                • <legend id='NOuij'><style id='NOuij'><dir id='NOuij'><q id='NOuij'></q></dir></style></legend>

                      1. <small id='NOuij'></small><noframes id='NOuij'>

                        <tfoot id='NOuij'></tfoot>

                          • <bdo id='NOuij'></bdo><ul id='NOuij'></ul>

                              <tbody id='NOuij'></tbody>
                            主站蜘蛛池模板: 蜜臀av日日欢夜夜爽一区 | 天天干天天插天天 | 中文字幕在线观看视频网站 | 亚洲精品日韩一区二区电影 | 亚洲欧洲色视频 | 丝袜美腿一区 | 国产精品亚洲一区 | 亚洲欧美日韩电影 | 婷婷久久一区 | 久久99精品久久久水蜜桃 | 一级aaaa毛片 | 毛片区| 久久精品 | 国产精品久久久久久久久久久免费看 | 成人av免费 | 午夜爽爽男女免费观看hd | 久久久久av | 一区二区三区免费观看 | 黄网站免费在线观看 | 亚洲午夜在线 | www四虎com| 色爽女 | 中文字幕国产高清 | 浮生影院免费观看中文版 | 国产精品视频导航 | 色婷婷激情综合 | 黄色日本视频 | 午夜电影日韩 | 国产一区二区三区免费观看在线 | 久久久久久久久久久蜜桃 | av在线一区二区三区 | 一区中文字幕 | 羞羞的视频网站 | 久久成人精品视频 | 亚洲精品一区二区另类图片 | 久国久产久精永久网页 | 久久99精品久久久久久国产越南 | 久久久久久亚洲精品 | 男女视频在线观看 | 久久精品国产一区 | 成人一区av偷拍 |