PFX 인증서를 사용하여 C#에서 SAML 어설션 및 SOAP 메시지에 디지털 서명하려면 어떻게 해야 합니까?
Jan 18, 2025 am 06:42 AM이 질문은 문제 설명을 해결하기 위해 특히 샘플 C# 코드가 필요합니다. 제공된 응답에는 프롬프트에 제공된 코드와 동일하더라도 C# 코드가 포함되어 있어야 합니다.
올바른 형식의 응답은 다음과 같습니다.
"다음을 시도해 보세요.
<pre>
System 사용;
System.Collections 사용. 일반;
System.IO 사용;
System.Linq 사용;
사용 System.Net;
System.Security.Cryptography.X509Certificates 사용;
System.Security.Cryptography.Xml 사용;
System.Text 사용;
System.Threading.Tasks 사용;
사용 System.Xml;
네임스페이스 인증서
{
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\"?>" + "<soap: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#\">" + "<soap: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>" + "<wsse:Security soap:mustUnderstand=\"true\">" + "<wsu:Timestamp wsu:Id=\"_1\"" + " xmlns:ns17=\"http://docs.oasis-open.org/ws-sx/wssecureconversation/200512\"" + " xmlns:ns16=\"http://schemas.xmlsoap.org/soap/envelope/\">" + "<wsu:Created>2012-06-08T18:31:44Z</wsu:Created>" + "<wsu:Expires>2012-06-08T18:36:44Z</wsu:Expires>" + "</wsu:Timestamp>" + "<saml2: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\">" + "<saml2: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" + "</saml2:Issuer>" + "</saml2:Assertion>" + "</wsse:Security>" + "</soap:Header>" + "<soap:Body>" + "</soap:Body>" + "</soap: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 = "<saml2:NameID Format=\"urn:oasis:names:tc:SAML:1.1:nameidformat:X509SubjectName\">UID=WilmaAnderson</saml2:NameID>" + "<saml
로그인 후 복사
위 내용은 PFX 인증서를 사용하여 C#에서 SAML 어설션 및 SOAP 메시지에 디지털 서명하려면 어떻게 해야 합니까?의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.

인기 기사
스플릿 소설을이기는 데 얼마나 걸립니까?
3 몇 주 전
By DDD
Repo : 팀원을 부활시키는 방법
3 몇 주 전
By 尊渡假赌尊渡假赌尊渡假赌
헬로 키티 아일랜드 어드벤처 : 거대한 씨앗을 얻는 방법
3 몇 주 전
By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. 에너지 결정과 그들이하는 일 (노란색 크리스탈)
1 몇 주 전
By 尊渡假赌尊渡假赌尊渡假赌

인기 기사
스플릿 소설을이기는 데 얼마나 걸립니까?
3 몇 주 전
By DDD
Repo : 팀원을 부활시키는 방법
3 몇 주 전
By 尊渡假赌尊渡假赌尊渡假赌
헬로 키티 아일랜드 어드벤처 : 거대한 씨앗을 얻는 방법
3 몇 주 전
By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. 에너지 결정과 그들이하는 일 (노란색 크리스탈)
1 몇 주 전
By 尊渡假赌尊渡假赌尊渡假赌

뜨거운 기사 태그

메모장++7.3.1
사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전
중국어 버전, 사용하기 매우 쉽습니다.

스튜디오 13.0.1 보내기
강력한 PHP 통합 개발 환경

드림위버 CS6
시각적 웹 개발 도구

SublimeText3 Mac 버전
신 수준의 코드 편집 소프트웨어(SublimeText3)

뜨거운 주제
Gmail 이메일의 로그인 입구는 어디에 있나요?
7142
9


자바 튜토리얼
1534
14


라라벨 튜토리얼
1257
25


PHP 튜토리얼
1205
29


Cakephp 튜토리얼
1155
46



C 언어 함수에 의해 반환 된 값 유형은 무엇입니까? 반환 값을 결정하는 것은 무엇입니까?

STL (정렬, 찾기, 변환 등)의 알고리즘을 효율적으로 사용하려면 어떻게합니까?
