当前位置: 首页>>代码示例>>C#>>正文


C# ProtectedString.EnableProtection方法代码示例

本文整理汇总了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
		}
开发者ID:olivierdagenais,项目名称:testoriented,代码行数:80,代码来源:Kdb4File.Write.cs


注:本文中的KeePassLib.Security.ProtectedString.EnableProtection方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。