本文整理汇总了C#中System.Text.UTF8Encoding.Trim方法的典型用法代码示例。如果您正苦于以下问题:C# UTF8Encoding.Trim方法的具体用法?C# UTF8Encoding.Trim怎么用?C# UTF8Encoding.Trim使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Text.UTF8Encoding
的用法示例。
在下文中一共展示了UTF8Encoding.Trim方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ParseAndVerifySamlToken
/// <summary>
/// Validates a SAML WSS user token.
/// </summary>
private SecurityToken ParseAndVerifySamlToken(byte[] tokenData)
{
XmlDocument document = new XmlDocument();
XmlNodeReader reader = null;
try
{
string text = new UTF8Encoding().GetString(tokenData);
document.InnerXml = text.Trim();
if (document.DocumentElement.NamespaceURI != "urn:oasis:names:tc:SAML:1.0:assertion")
{
throw new ServiceResultException(StatusCodes.BadNotSupported);
}
reader = new XmlNodeReader(document.DocumentElement);
SecurityToken samlToken = new SamlSerializer().ReadToken(
reader,
m_tokenSerializer,
m_tokenResolver);
return samlToken;
}
catch (Exception e)
{
// construct translation object with default text.
TranslationInfo info = new TranslationInfo(
"InvalidSamlToken",
"en-US",
"'{0}' is not a valid SAML token.",
document.DocumentElement.LocalName);
// create an exception with a vendor defined sub-code.
throw new ServiceResultException(new ServiceResult(
e,
StatusCodes.BadIdentityTokenRejected,
"InvalidSamlToken",
"http://opcfoundation.org/UA/Sample/",
new LocalizedText(info)));
}
finally
{
if (reader != null)
{
reader.Close();
}
}
}
示例2: Initialize
/// <summary>
/// Initializes the object with a UA identity token
/// </summary>
private void Initialize(IssuedIdentityToken token, SecurityTokenSerializer serializer, SecurityTokenResolver resolver)
{
if (token == null) throw new ArgumentNullException("token");
string text = new UTF8Encoding().GetString(token.DecryptedTokenData);
XmlDocument document = new XmlDocument();
document.InnerXml = text.Trim();
XmlNodeReader reader = new XmlNodeReader(document.DocumentElement);
try
{
if (document.DocumentElement.NamespaceURI == "urn:oasis:names:tc:SAML:1.0:assertion")
{
SecurityToken samlToken = new SamlSerializer().ReadToken(reader, serializer, resolver);
Initialize(samlToken);
}
else
{
SecurityToken securityToken = serializer.ReadToken(reader, resolver);
Initialize(securityToken);
}
}
finally
{
reader.Close();
}
}