这个问题特别需要示例 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.Xml;<p>命名空间证书<br>{</p><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);
body.InnerXml = Encoding.UTF8.GetString(xmlBytes);
} 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></saml>
以上是如何使用 PFX 证书在 C# 中对 SAML 断言和 SOAP 消息进行数字签名?的详细内容。更多信息请关注PHP中文网其他相关文章!

本文解释了C标准模板库(STL),重点关注其核心组件:容器,迭代器,算法和函子。 它详细介绍了这些如何交互以启用通用编程,提高代码效率和可读性t

本文详细介绍了c中有效的STL算法用法。 它强调了数据结构选择(向量与列表),算法复杂性分析(例如,std :: sort vs. std vs. std :: partial_sort),迭代器用法和并行执行。 常见的陷阱

本文详细介绍了C中的有效异常处理,涵盖了尝试,捕捉和投掷机制。 它强调了诸如RAII之类的最佳实践,避免了不必要的捕获块,并为强大的代码登录例外。 该文章还解决了Perf

本文讨论了使用C中的移动语义来通过避免不必要的复制来提高性能。它涵盖了使用std :: Move的实施移动构造函数和任务运算符,并确定了关键方案和陷阱以有效

C 20范围通过表现力,合成性和效率增强数据操作。它们简化了复杂的转换并集成到现有代码库中,以提高性能和可维护性。

本文讨论了C中的动态调度,其性能成本和优化策略。它突出了动态调度会影响性能并将其与静态调度进行比较的场景,强调性能和之间的权衡

文章讨论了在C中有效使用RVALUE参考,以进行移动语义,完美的转发和资源管理,重点介绍最佳实践和性能改进。(159个字符)


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

EditPlus 中文破解版
体积小,语法高亮,不支持代码提示功能

ZendStudio 13.5.1 Mac
功能强大的PHP集成开发环境

VSCode Windows 64位 下载
微软推出的免费、功能强大的一款IDE编辑器

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

Dreamweaver Mac版
视觉化网页开发工具