本文整理汇总了C#中KeePassLib.Security.ProtectedString.EnableProtection方法的典型用法代码示例。如果您正苦于以下问题:C# ProtectedString.EnableProtection方法的具体用法?C# ProtectedString.EnableProtection怎么用?C# ProtectedString.EnableProtection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类KeePassLib.Security.ProtectedString
的用法示例。
在下文中一共展示了ProtectedString.EnableProtection方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WriteObject
private void WriteObject(string name, ProtectedString value, bool bIsEntryString)
{
Debug.Assert(name != null);
Debug.Assert(value != null); if(value == null) throw new ArgumentNullException("value");
m_xmlWriter.WriteStartElement(ElemString);
m_xmlWriter.WriteStartElement(ElemKey);
m_xmlWriter.WriteString(StrUtil.SafeXmlString(name));
m_xmlWriter.WriteEndElement();
m_xmlWriter.WriteStartElement(ElemValue);
if(bIsEntryString)
{
if(name == PwDefs.TitleField)
value.EnableProtection(m_pwDatabase.MemoryProtection.ProtectTitle);
else if(name == PwDefs.UserNameField)
value.EnableProtection(m_pwDatabase.MemoryProtection.ProtectUserName);
else if(name == PwDefs.PasswordField)
value.EnableProtection(m_pwDatabase.MemoryProtection.ProtectPassword);
else if(name == PwDefs.UrlField)
value.EnableProtection(m_pwDatabase.MemoryProtection.ProtectUrl);
else if(name == PwDefs.NotesField)
value.EnableProtection(m_pwDatabase.MemoryProtection.ProtectNotes);
}
if(value.IsProtected && (m_format != Kdb4Format.PlainXml))
{
m_xmlWriter.WriteAttributeString(AttrProtected, ValTrue);
byte[] pbEncoded = value.ReadXorredString(m_randomStream);
if(pbEncoded.Length > 0)
m_xmlWriter.WriteBase64(pbEncoded, 0, pbEncoded.Length);
}
else
{
string strValue = value.ReadString();
// If names should be localized, we need to apply the language-dependent
// string transformation here. By default, language-dependent conversions
// should be applied, otherwise characters could be rendered incorrectly
// (code page problems).
if(m_bLocalizedNames)
{
StringBuilder sb = new StringBuilder();
foreach(char ch in strValue)
{
char chMapped = ch;
// Symbols and surrogates must be moved into the correct code
// page area
if(char.IsSymbol(ch) || char.IsSurrogate(ch))
{
System.Globalization.UnicodeCategory cat = char.GetUnicodeCategory(ch);
// Map character to correct position in code page
chMapped = (char)((int)cat * 32 + ch);
}
else if(char.IsControl(ch))
{
if(ch >= 256) // Control character in high ANSI code page
{
// Some of the control characters map to corresponding ones
// in the low ANSI range (up to 255) when calling
// ToLower on them with invariant culture (see
// http://lists.ximian.com/pipermail/mono-patches/2002-February/086106.html )
chMapped = char.ToLower(ch, CultureInfo.InvariantCulture);
}
}
sb.Append(chMapped);
}
strValue = sb.ToString(); // Correct string for current code page
}
m_xmlWriter.WriteString(StrUtil.SafeXmlString(strValue));
}
m_xmlWriter.WriteEndElement(); // ElemValue
m_xmlWriter.WriteEndElement(); // ElemString
}