這個問題特別需要範例 C# 程式碼才能解決問題陳述。提供的回應應包含 C# 程式碼,即使它與提示中提供的程式碼相同。
正確格式的回應應如下所示:
「嘗試執行以下操作:
<br> 使用System;<br> 使用System.Collections。通用;<br> 使用System.IO;<br> 使用System.Linq;<br>使用System.Net;<br> 使用 System.Security.Cryptography.X509Certificates;<br> 使用 System.Security.Cryptography.Xml;<br> 使用 System.Text;<br> 使用 System.Threading.Tasks;<br> 使用 System.Text; 使用 System.Threading.Tasks;<p> 使用 System.Text;<br> 使用 System.Threading.Tasks;</p> 使用 System.Text;<pre class="brush:php;toolbar:false">class Program { const string FILENAME = @"c:\temp\test.xml"; static void Main(string[] args) { XmlDocument doc = new XmlDocument(); CreateSoap(doc); XmlElement assertion = (XmlElement)(doc.GetElementsByTagName("saml2:Assertion")[0]); XmlElement security = (XmlElement)(doc.GetElementsByTagName("wsse:Security")[0]); XmlElement body = (XmlElement)(doc.GetElementsByTagName("soap:Body")[0]); using (WebClient client = new WebClient()) { byte[] xmlBytes = client.DownloadData(FILENAME);使用 System.Threading.Tasks;
使用 System.Text;
使用 System.Threading.Tasks;} string pfxpath = @"D:\Certificate\Private-cert.pfx"; X509Certificate2 cert = new X509Certificate2(File.ReadAllBytes(pfxpath), "123456789"); SignXmlWithCertificate(assertion, cert); SignXmlWithCertificate(security, cert); //added 10-20-17 XmlElement subject = doc.CreateElement("Subject", "saml2"); assertion.AppendChild(subject); CreateSubject(subject); File.WriteAllText(@"D:\Certificate\digitallysigned.xml", doc.OuterXml); } public static void CreateSoap(XmlDocument doc) { DateTime date = DateTime.Now; string soap = string.Format( "<?xml version=\"1.0\"?>" + "<envelope xmlns:soap='\"http://www.w3.org/2003/05/soap-envelope\""' xmlns:wsse11='\"http://docs.oasisopen.org/wss/oasis-wss-wssecurity-secext-1.1.xsd\""' xmlns:wsse='\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd\""' xmlns:wsu='\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wsswssecurity-utility-1.0.xsd\""' xmlns:xs='\"http://www.w3.org/2001/XMLSchema\""' xmlns:ds='\"http://www.w3.org/2000/09/xmldsig#\""' xmlns:saml='\"urn:oasis:names:tc:SAML:1.0:assertion\""' xmlns:exc14n='\"http://www.w3.org/2001/10/xml-exc-c14n#\"'>" + "<header>" + "<to mustunderstand='\"true\""' xmlns='\"http://www.w3.org/2005/08/addressing\"'>https://localhost:443/Gateway/PatientDiscovery/1_0/NwHINService/NwHINPatientDiscovery" + "</to>" + "<action mustunderstand='\"true\""' xmlns='\"http://www.w3.org/2005/08/addressing\"'>urn:hl7-org:v3:PRPA_IN201305UV02:CrossGatewayPatientDiscovery" + "</action>" + "<replyto mustunderstand='\"true\""' xmlns='\"http://www.w3.org/2005/08/addressing\"'>" + "<address>http://www.w3.org/2005/08/addressing/anonymous</address>" + "</replyto>" + "<messageid mustunderstand='\"true\""' xmlns='\"http://www.w3.org/2005/08/addressing\"'>461433e3-4591-453b-9eb6-791c7f5ff882" + "</messageid>" + "<security soap:mustunderstand='\"true\"'>" + "<timestamp wsu:id='\"_1\""' xmlns:ns17='\"http://docs.oasis-open.org/ws-sx/wssecureconversation/200512\""' xmlns:ns16='\"http://schemas.xmlsoap.org/soap/envelope/\"'>" + "<created>2012-06-08T18:31:44Z</created>" + "<expires>2012-06-08T18:36:44Z</expires>" + "</timestamp>" + "<assertion id='\"_883e64a747a5449b83821913a2b189e6\"' issueinstant='\"{0}\"' version='\"2.0\""' xmlns:ds='\"http://www.w3.org/2000/09/xmldsig#\""' xmlns:exc14n='\"http://www.w3.org/2001/10/xml-excc14n#\""' xmlns:saml2='\"urn:oasis:names:tc:SAML:2.0:assertion\""' xmlns:xenc='\"http://www.w3.org/2001/04/xmlenc#\""' xmlns:xs='\"http://www.w3.org/2001/XMLSchema\"'>" + "<issuer format='\"urn:oasis:names:tc:SAML:1.1:nameid-format:X509SubjectName\"'>CN=SAML User,OU=SU,O=SAML User,L=Los Angeles,ST=CA,C=US" + "</issuer>" + "</assertion>" + "</security>" + "</header>" + "<body>" + "</body>" + "</envelope>", date.ToUniversalTime().ToString("yyyy-MM-ddThh:mm:ss.fffZ")); doc.LoadXml(soap); } public static void SignXmlWithCertificate(XmlElement assertion, X509Certificate2 cert) { SignedXml signedXml = new SignedXml(assertion); signedXml.SigningKey = cert.PrivateKey; Reference reference = new Reference(); reference.Uri = ""; reference.AddTransform(new XmlDsigEnvelopedSignatureTransform()); signedXml.AddReference(reference); KeyInfo keyInfo = new KeyInfo(); keyInfo.AddClause(new KeyInfoX509Data(cert)); signedXml.KeyInfo = keyInfo; signedXml.ComputeSignature(); XmlElement xmlsig = signedXml.GetXml(); assertion.AppendChild(xmlsig); } public static void CreateSubject(XmlElement xSubject) { string subject = "<nameid format='\"urn:oasis:names:tc:SAML:1.1:nameidformat:X509SubjectName\"'>UID=WilmaAnderson</nameid>" + "<saml> 使用 System.Text; 使用 System.Threading.Tasks; 使用 System.Text; 使用 System.Threading.Tasks; 用 System.使用System.Xml;命名空間憑證{body.InnerXml = Encoding.UTF8.GetString(xmlBytes);</saml>
以上是如何使用 PFX 憑證在 C# 中對 SAML 斷言和 SOAP 訊息進行數位簽章?的詳細內容。更多資訊請關注PHP中文網其他相關文章!

在C 中使用XML是因為它提供了結構化數據的便捷方式,尤其在配置文件、數據存儲和網絡通信中不可或缺。 1)選擇合適的庫,如TinyXML、pugixml、RapidXML,根據項目需求決定。 2)了解XML解析和生成的兩種方式:DOM適合頻繁訪問和修改,SAX適用於大文件或流數據。 3)優化性能時,TinyXML適合小文件,pugixml在內存和速度上表現好,RapidXML處理大文件優異。

C#和C 的主要區別在於內存管理、多態性實現和性能優化。 1)C#使用垃圾回收器自動管理內存,C 則需要手動管理。 2)C#通過接口和虛方法實現多態性,C 使用虛函數和純虛函數。 3)C#的性能優化依賴於結構體和並行編程,C 則通過內聯函數和多線程實現。

C 中解析XML數據可以使用DOM和SAX方法。 1)DOM解析將XML加載到內存,適合小文件,但可能佔用大量內存。 2)SAX解析基於事件驅動,適用於大文件,但無法隨機訪問。選擇合適的方法並優化代碼可提高效率。

C 在遊戲開發、嵌入式系統、金融交易和科學計算等領域中的應用廣泛,原因在於其高性能和靈活性。 1)在遊戲開發中,C 用於高效圖形渲染和實時計算。 2)嵌入式系統中,C 的內存管理和硬件控制能力使其成為首選。 3)金融交易領域,C 的高性能滿足實時計算需求。 4)科學計算中,C 的高效算法實現和數據處理能力得到充分體現。

C 沒有死,反而在許多關鍵領域蓬勃發展:1)遊戲開發,2)系統編程,3)高性能計算,4)瀏覽器和網絡應用,C 依然是主流選擇,展現了其強大的生命力和應用場景。

C#和C 的主要區別在於語法、內存管理和性能:1)C#語法現代,支持lambda和LINQ,C 保留C特性並支持模板。 2)C#自動內存管理,C 需要手動管理。 3)C 性能優於C#,但C#性能也在優化中。

在C 中處理XML數據可以使用TinyXML、Pugixml或libxml2庫。 1)解析XML文件:使用DOM或SAX方法,DOM適合小文件,SAX適合大文件。 2)生成XML文件:將數據結構轉換為XML格式並寫入文件。通過這些步驟,可以有效地管理和操作XML數據。

在C 中處理XML數據結構可以使用TinyXML或pugixml庫。 1)使用pugixml庫解析和生成XML文件。 2)處理複雜的嵌套XML元素,如書籍信息。 3)優化XML處理代碼,建議使用高效庫和流式解析。通過這些步驟,可以高效處理XML數據。


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

禪工作室 13.0.1
強大的PHP整合開發環境

DVWA
Damn Vulnerable Web App (DVWA) 是一個PHP/MySQL的Web應用程序,非常容易受到攻擊。它的主要目標是成為安全專業人員在合法環境中測試自己的技能和工具的輔助工具,幫助Web開發人員更好地理解保護網路應用程式的過程,並幫助教師/學生在課堂環境中教授/學習Web應用程式安全性。 DVWA的目標是透過簡單直接的介面練習一些最常見的Web漏洞,難度各不相同。請注意,該軟體中

VSCode Windows 64位元 下載
微軟推出的免費、功能強大的一款IDE編輯器

SAP NetWeaver Server Adapter for Eclipse
將Eclipse與SAP NetWeaver應用伺服器整合。

PhpStorm Mac 版本
最新(2018.2.1 )專業的PHP整合開發工具