1
我有一个基于Web的应用程序,其中使用SAML(作为服务提供商)的SSO已实施。 它涉及数字签名验证。如果在XML响应中没有unicode字符(如'ü')发布到系统中,则以下代码可以正常工作。SSO SAML数字签名验证 - XML unicode字符
但是,对于UNICODE字符,它在将XML加载到XMLDocument类时引发异常。如果我将XML响应保存在使用Unicode格式的记事本文件中,并读取数字签名验证的相同内容,那么事情工作正常。我需要在C#实现中使用记事本手动步骤。
以下是我正在使用的代码。
if (m_b64SamlResponse == null || m_b64SamlResponse == string.Empty)
return "SAMLResponse null or empty";
string xml = Decode(m_b64SamlResponse);
m_xmlDoc = new XmlDocument();
m_xmlDoc.PreserveWhitespace = true;
m_xmlDoc.LoadXml(xml);
XmlNamespaceManager nsm = new XmlNamespaceManager(new NameTable());
nsm.AddNamespace("dsig", SignedXml.XmlDsigNamespaceUrl);
XmlElement sigElt = (XmlElement)xd.SelectSingleNode(
"//dsig:Signature", nsm);
// Load the signature for verification
SignedXml sig = new SignedXml(m_xmlDoc);
sig.LoadXml(sigElt);
if (!sig.CheckSignature())
return "Invalid Signature";
else
return "Valid Signature";