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


C# ProtectedString.ReadString方法代码示例

本文整理汇总了C#中KeePassLib.Security.ProtectedString.ReadString方法的典型用法代码示例。如果您正苦于以下问题:C# ProtectedString.ReadString方法的具体用法?C# ProtectedString.ReadString怎么用?C# ProtectedString.ReadString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在KeePassLib.Security.ProtectedString的用法示例。


在下文中一共展示了ProtectedString.ReadString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Copy

		public static bool Copy(ProtectedString psToCopy, bool bIsEntryInfo,
			PwEntry peEntryInfo, PwDatabase pwReferenceSource)
		{
			Debug.Assert(psToCopy != null);
			if(psToCopy == null) throw new ArgumentNullException("psToCopy");

			if(bIsEntryInfo && !AppPolicy.Try(AppPolicyId.CopyToClipboard))
				return false;

			string strData = SprEngine.Compile(psToCopy.ReadString(), false,
				peEntryInfo, pwReferenceSource, false, false);

			try
			{
				ClipboardUtil.Clear();

				DataObject doData = CreateProtectedDataObject(strData);
				Clipboard.SetDataObject(doData);

				m_pbDataHash32 = HashClipboard();
				m_strFormat = null;

				RaiseCopyEvent(bIsEntryInfo, strData);
			}
			catch(Exception) { Debug.Assert(false); return false; }

			if(peEntryInfo != null) peEntryInfo.Touch(false);

			// SprEngine.Compile might have modified the database
			Program.MainForm.UpdateUI(false, null, false, null, false, null, false);

			return true;
		}
开发者ID:ComradeP,项目名称:KeePass-2.x,代码行数:33,代码来源:ClipboardUtil.cs

示例2: Copy

		public static bool Copy(ProtectedString psToCopy, bool bIsEntryInfo,
			PwEntry peEntryInfo, PwDatabase pwReferenceSource)
		{
			if(psToCopy == null) throw new ArgumentNullException("psToCopy");
			return Copy(psToCopy.ReadString(), true, bIsEntryInfo, peEntryInfo,
				pwReferenceSource, IntPtr.Zero);
		}
开发者ID:dbremner,项目名称:keepass2,代码行数:7,代码来源:ClipboardUtil.cs

示例3: ExpandPattern

public void ExpandPattern()
{
    // arrange
    var psOutBuffer = new ProtectedString();
    var pwProfile = new PwProfile();
    pwProfile.Pattern = "g{5}";
    var pbKey = new byte[] { 0x00 };
    var crsRandomSource = new CryptoRandomStream(CrsAlgorithm.Salsa20, pbKey);
    var error = PatternBasedGenerator.Generate(psOutBuffer, pwProfile, crsRandomSource);

    // act
    // nothing to do as ExpandPattern() would have been called by calling Generate()

    // assert
    Assert.AreEqual(PwgError.Success, error);
    var actual = psOutBuffer.ReadString();
    Assert.AreEqual("ggggg", actual);
}
开发者ID:olivierdagenais,项目名称:testoriented,代码行数:18,代码来源:PatternBasedGeneratorTest.cs

示例4: FillIfExists

        private static string FillIfExists(string strData, string strPlaceholder,
            ProtectedString psParsable, PwEntry pwEntry, PwDatabase pwDatabase,
            SprContentFlags cf, uint uRecursionLevel, SprRefsCache vRefsCache)
        {
            // The UrlRemoveSchemeOnce property of cf must be cleared
            // before this method returns and before any recursive call
            bool bRemoveScheme = false;
            if(cf != null)
            {
                bRemoveScheme = cf.UrlRemoveSchemeOnce;
                cf.UrlRemoveSchemeOnce = false;
            }

            if(strData == null) { Debug.Assert(false); return string.Empty; }
            if(strPlaceholder == null) { Debug.Assert(false); return strData; }
            if(strPlaceholder.Length == 0) { Debug.Assert(false); return strData; }
            if(psParsable == null) { Debug.Assert(false); return strData; }

            if(strData.IndexOf(strPlaceholder, SprEngine.ScMethod) >= 0)
            {
                string strReplacement = SprEngine.CompileInternal(
                    psParsable.ReadString(), pwEntry, pwDatabase, null,
                    uRecursionLevel + 1, vRefsCache);

                if(bRemoveScheme) strReplacement = UrlUtil.RemoveScheme(strReplacement);

                return SprEngine.FillPlaceholder(strData, strPlaceholder,
                    strReplacement, cf);
            }

            return strData;
        }
开发者ID:elitak,项目名称:keepass,代码行数:32,代码来源:SprEngine.cs

示例5: ProtectedString

		/// <summary>
		/// Construct a new protected string. The string is initialized
		/// to the value passed in the <c>pbTemplate</c> protected string.
		/// </summary>
		/// <param name="psTemplate">The initial string value. This
		/// parameter won't be modified. Must not be <c>null</c>.</param>
		/// <exception cref="System.ArgumentNullException">Thrown if the input
		/// parameter is <c>null</c>.</exception>
		public ProtectedString(ProtectedString psTemplate)
		{
			Debug.Assert(psTemplate != null);
			if(psTemplate == null) throw new ArgumentNullException("psTemplate");

			try { m_secString = new SecureString(); }
			catch(NotSupportedException) { } // Windows 98 / ME

			m_bIsProtected = psTemplate.m_bIsProtected;
			SetString(psTemplate.ReadString());
		}
开发者ID:miracle2k,项目名称:keepass2,代码行数:19,代码来源:ProtectedString_111029.cs

示例6: CopyAndMinimize

        public static bool CopyAndMinimize(ProtectedString psToCopy, bool bIsEntryInfo,
			Form formContext, PwEntry peEntryInfo, PwDatabase pwReferenceSource)
        {
            if(psToCopy == null) throw new ArgumentNullException("psToCopy");

            IntPtr hOwner = ((formContext != null) ? formContext.Handle : IntPtr.Zero);

            if(Copy(psToCopy.ReadString(), true, bIsEntryInfo, peEntryInfo,
                pwReferenceSource, hOwner))
            {
                if(formContext != null)
                {
                    if(Program.Config.MainWindow.DropToBackAfterClipboardCopy)
                        NativeMethods.LoseFocus(formContext);

                    if(Program.Config.MainWindow.MinimizeAfterClipboardCopy)
                        UIUtil.SetWindowState(formContext, FormWindowState.Minimized);
                }

                return true;
            }

            return false;
        }
开发者ID:saadware,项目名称:kpn,代码行数:24,代码来源:ClipboardUtil.cs

示例7: GeneratePassword

        public string GeneratePassword(string profileName)
        {
            PwProfile profile = null;

            if (string.IsNullOrEmpty(profileName))
                profile = KeePass.Program.Config.PasswordGenerator.LastUsedProfile;
            else
            {
                foreach (PwProfile pp in KeePass.Program.Config.PasswordGenerator.UserProfiles)
                {
                    if (pp.Name == profileName)
                    {
                        profile = pp;
                        break;
                    }
                }
            }

            if (profile == null)
                return "";

            ProtectedString newPassword = new ProtectedString();
            PwgError result = PwGenerator.Generate(newPassword, profile, null, null);

            if (result == PwgError.Success)
                return newPassword.ReadString();
            else
                return "";

            //KeePass.Program.Config.PasswordGenerator.AutoGeneratedPasswordsProfile.Name

            ////KeePassLib.Cryptography.PasswordGenerator.PwProfile profile = new KeePassLib.Cryptography.PasswordGenerator.PwProfile();//host.PwGeneratorPool.Find(
            ////KeePass.Program.PwGeneratorPool
            // //KeePass.Util.PwGeneratorUtil.
            //profile.
            //KeePassLib.Security
            //KeePassLib.Cryptography.PasswordGenerator.PwGenerator.Generate(null, KeePassLib.Cryptography.PasswordGenerator.PwProfile
            //foreach (PwProfile pwgo in host.PwGeneratorPool.Config.PasswordGenerator.UserProfiles)
            //{
            //    if (pwgo.Name == strProfile)
            //    {
            //        SetGenerationOptions(pwgo);
            //        break;
            //    }
            //}
            //return "password";
        }
开发者ID:krbvroc1,项目名称:KeeFox,代码行数:47,代码来源:KeePassRPCService.cs

示例8: TestProtectedObjects

        private static void TestProtectedObjects()
        {
            #if DEBUG
            Encoding enc = StrUtil.Utf8;

            byte[] pbData = enc.GetBytes("Test Test Test Test");
            ProtectedBinary pb = new ProtectedBinary(true, pbData);
            if(!pb.IsProtected) throw new SecurityException("ProtectedBinary-1");

            byte[] pbDec = pb.ReadData();
            if(!MemUtil.ArraysEqual(pbData, pbDec))
                throw new SecurityException("ProtectedBinary-2");
            if(!pb.IsProtected) throw new SecurityException("ProtectedBinary-3");

            byte[] pbData2 = enc.GetBytes("Test Test Test Test");
            byte[] pbData3 = enc.GetBytes("Test Test Test Test Test");
            ProtectedBinary pb2 = new ProtectedBinary(true, pbData2);
            ProtectedBinary pb3 = new ProtectedBinary(true, pbData3);
            if(!pb.Equals(pb2)) throw new SecurityException("ProtectedBinary-4");
            if(pb.Equals(pb3)) throw new SecurityException("ProtectedBinary-5");
            if(pb2.Equals(pb3)) throw new SecurityException("ProtectedBinary-6");

            if(pb.GetHashCode() != pb2.GetHashCode())
                throw new SecurityException("ProtectedBinary-7");
            if(!((object)pb).Equals((object)pb2))
                throw new SecurityException("ProtectedBinary-8");
            if(((object)pb).Equals((object)pb3))
                throw new SecurityException("ProtectedBinary-9");
            if(((object)pb2).Equals((object)pb3))
                throw new SecurityException("ProtectedBinary-10");

            ProtectedString ps = new ProtectedString();
            if(ps.Length != 0) throw new SecurityException("ProtectedString-1");
            if(!ps.IsEmpty) throw new SecurityException("ProtectedString-2");
            if(ps.ReadString().Length != 0)
                throw new SecurityException("ProtectedString-3");

            ps = new ProtectedString(true, "Test");
            ProtectedString ps2 = new ProtectedString(true, enc.GetBytes("Test"));
            if(ps.IsEmpty) throw new SecurityException("ProtectedString-4");
            pbData = ps.ReadUtf8();
            pbData2 = ps2.ReadUtf8();
            if(!MemUtil.ArraysEqual(pbData, pbData2))
                throw new SecurityException("ProtectedString-5");
            if(pbData.Length != 4)
                throw new SecurityException("ProtectedString-6");
            if(ps.ReadString() != ps2.ReadString())
                throw new SecurityException("ProtectedString-7");
            pbData = ps.ReadUtf8();
            pbData2 = ps2.ReadUtf8();
            if(!MemUtil.ArraysEqual(pbData, pbData2))
                throw new SecurityException("ProtectedString-8");
            if(!ps.IsProtected) throw new SecurityException("ProtectedString-9");
            if(!ps2.IsProtected) throw new SecurityException("ProtectedString-10");
            #endif
        }
开发者ID:pythe,项目名称:wristpass,代码行数:56,代码来源:SelfTest.cs

示例9: GeneratePassword

        public string GeneratePassword(string profileName)
        {
            PwProfile profile = null;

            if (string.IsNullOrEmpty(profileName))
                profile = KeePass.Program.Config.PasswordGenerator.LastUsedProfile;
            else
            {
                foreach (PwProfile pp in KeePass.Util.PwGeneratorUtil.GetAllProfiles(false))
                {
                    if (pp.Name == profileName)
                    {
                        profile = pp;
                        KeePass.Program.Config.PasswordGenerator.LastUsedProfile = pp;
                        break;
                    }
                }
            }

            if (profile == null)
                return "";

            ProtectedString newPassword = new ProtectedString();
            PwgError result = PwgError.Unknown; // PwGenerator.Generate(out newPassword, profile, null, null);

            MethodInfo mi;

            // Generate method signature changed in KP 2.18 so we use
            // reflection to enable support for both 2.18 and earlier versions
            Type[] mitypes218 = new Type[] { typeof(ProtectedString).MakeByRefType(), typeof(PwProfile), typeof(byte[]), typeof(CustomPwGeneratorPool) };

            try
            {
                mi = typeof(PwGenerator).GetMethod(
                    "Generate",
                    BindingFlags.Public | BindingFlags.Static,
                    Type.DefaultBinder,
                    mitypes218,
                    null
                );

                object[] inputParameters = new object[] { null, profile, null, this.host.PwGeneratorPool };
                result = (PwgError)mi.Invoke(null, inputParameters);
                newPassword = (ProtectedString)inputParameters[0];
            }
            catch (Exception)
            {
                Type[] mitypes217 = new Type[] { typeof(ProtectedString), typeof(PwProfile), typeof(byte[]), typeof(CustomPwGeneratorPool) };
                // can't find the 2.18 method definition so try for an earlier version
                mi = typeof(PwGenerator).GetMethod(
                    "Generate",
                    BindingFlags.Public | BindingFlags.Static,
                    Type.DefaultBinder,
                    mitypes217,
                    null
                );

                object[] inputParameters = new object[] { newPassword, profile, null, this.host.PwGeneratorPool };
                result = (PwgError)mi.Invoke(null, inputParameters);

                // If an exception is thrown here it would be unexpected and
                // require a new version of the application to be released
            }

            if (result == PwgError.Success)
                return newPassword.ReadString();
            else
                return "";

            //KeePass.Program.Config.PasswordGenerator.AutoGeneratedPasswordsProfile.Name

            ////KeePassLib.Cryptography.PasswordGenerator.PwProfile profile = new KeePassLib.Cryptography.PasswordGenerator.PwProfile();//host.PwGeneratorPool.Find(
            ////KeePass.Program.PwGeneratorPool
            // //KeePass.Util.PwGeneratorUtil.
            //profile.
            //KeePassLib.Security
            //KeePassLib.Cryptography.PasswordGenerator.PwGenerator.Generate(null, KeePassLib.Cryptography.PasswordGenerator.PwProfile
            //foreach (PwProfile pwgo in host.PwGeneratorPool.Config.PasswordGenerator.UserProfiles)
            //{
            //    if (pwgo.Name == strProfile)
            //    {
            //        SetGenerationOptions(pwgo);
            //        break;
            //    }
            //}
            //return "password";
        }
开发者ID:kkchia,项目名称:KeeFox,代码行数:87,代码来源:KeePassRPCService.cs

示例10: 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);

            bool bProtected = value.IsProtected;
            if(bIsEntryString)
            {
                // Adjust memory protection setting (which might be different
                // from the database default, e.g. due to an import which
                // didn't specify the correct setting)
                if(name == PwDefs.TitleField)
                    bProtected = m_pwDatabase.MemoryProtection.ProtectTitle;
                else if(name == PwDefs.UserNameField)
                    bProtected = m_pwDatabase.MemoryProtection.ProtectUserName;
                else if(name == PwDefs.PasswordField)
                    bProtected = m_pwDatabase.MemoryProtection.ProtectPassword;
                else if(name == PwDefs.UrlField)
                    bProtected = m_pwDatabase.MemoryProtection.ProtectUrl;
                else if(name == PwDefs.NotesField)
                    bProtected = m_pwDatabase.MemoryProtection.ProtectNotes;
            }

            if(bProtected && (m_format != KdbxFormat.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 =
                                CharUnicodeInfo.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 )
            #if !KeePassLibSD
                                chMapped = char.ToLowerInvariant(ch);
            #else
                                chMapped = char.ToLower(ch);
            #endif
                            }
                        }

                        sb.Append(chMapped);
                    }

                    strValue = sb.ToString(); // Correct string for current code page
                }

                if((m_format == KdbxFormat.PlainXml) && bProtected)
                    m_xmlWriter.WriteAttributeString(AttrProtectedInMemPlainXml, ValTrue);

                m_xmlWriter.WriteString(StrUtil.SafeXmlString(strValue));
            }

            m_xmlWriter.WriteEndElement(); // ElemValue
            m_xmlWriter.WriteEndElement(); // ElemString
        }
开发者ID:Stoom,项目名称:KeePass,代码行数:92,代码来源:KdbxFile.Write.cs

示例11: ReplaceNewPasswordPlaceholder

		private static string ReplaceNewPasswordPlaceholder(string strText,
			PwEntry pe, PwDatabase pd, SprContentFlags cf)
		{
			if((pe == null) || (pd == null)) return strText;

			string str = strText;

			const string strNewPwPlh = @"{NEWPASSWORD}";
			if(str.IndexOf(strNewPwPlh, StrUtil.CaseIgnoreCmp) >= 0)
			{
				ProtectedString psAutoGen = new ProtectedString(
					pd.MemoryProtection.ProtectPassword);
				PwgError e = PwGenerator.Generate(psAutoGen,
					Program.Config.PasswordGenerator.AutoGeneratedPasswordsProfile,
					null, Program.PwGeneratorPool);

				if(e == PwgError.Success)
				{
					pe.CreateBackup();
					pe.Strings.Set(PwDefs.PasswordField, psAutoGen);
					pd.Modified = true;

					string strIns = SprEngine.TransformContent(psAutoGen.ReadString(), cf);
					str = StrUtil.ReplaceCaseInsensitive(str, strNewPwPlh, strIns);
				}
			}

			return str;
		}
开发者ID:ComradeP,项目名称:KeePass-2.x,代码行数:29,代码来源:EntryUtil.cs

示例12: WriteBase

 public WriteBase(ProtectedString masterkey, PwDatabase database)
 {
     _dataConnections.UserPass = masterkey.ReadString();
     this._kpDatabase = database;
     InitializeComponent();
 }
开发者ID:dc914337,项目名称:PSD-KeePass2-Plugin,代码行数:6,代码来源:WriteBase.cs

示例13: GeneratePreviewPasswords

        private void GeneratePreviewPasswords()
        {
            m_pbPreview.Value = 0;
            m_tbPreview.Text = string.Empty;

            PwProfile pwOpt = GetGenerationOptions();
            StringBuilder sbList = new StringBuilder();

            Cursor cNormalCursor = this.Cursor;
            this.Cursor = Cursors.WaitCursor;

            for(uint i = 0; i < MaxPreviewPasswords; ++i)
            {
                Application.DoEvents();

                ProtectedString psNew = new ProtectedString(false);
                PwGenerator.Generate(psNew, pwOpt, null, Program.PwGeneratorPool);
                sbList.AppendLine(psNew.ReadString());
                m_pbPreview.Value = (int)((100 * i) / MaxPreviewPasswords);
            }

            m_pbPreview.Value = 100;
            m_tbPreview.Text = sbList.ToString();

            this.Cursor = cNormalCursor;
        }
开发者ID:amiryal,项目名称:keepass2,代码行数:26,代码来源:PwGeneratorForm.cs

示例14: FillIfExists

        private static string FillIfExists(string strData, string strPlaceholder,
            ProtectedString psParsable, PwEntry pwEntry, PwDatabase pwDatabase,
            SprContentFlags cf, uint uRecursionLevel, SprRefsCache vRefsCache)
        {
            if(strData == null) { Debug.Assert(false); return string.Empty; }
            if(strPlaceholder == null) { Debug.Assert(false); return strData; }
            if(strPlaceholder.Length == 0) { Debug.Assert(false); return strData; }
            if(psParsable == null) { Debug.Assert(false); return strData; }

            if(strData.IndexOf(strPlaceholder, SprEngine.ScMethod) >= 0)
                return SprEngine.FillPlaceholder(strData, strPlaceholder,
                    SprEngine.CompileInternal(psParsable.ReadString(), pwEntry,
                    pwDatabase, null, uRecursionLevel + 1, vRefsCache), cf);

            return strData;
        }
开发者ID:jonbws,项目名称:strengthreport,代码行数:16,代码来源:SprEngine.cs

示例15: TestProtectedObjects

		private static void TestProtectedObjects()
		{
#if DEBUG
			Encoding enc = StrUtil.Utf8;

			byte[] pbData = enc.GetBytes("Test Test Test Test");
			ProtectedBinary pb = new ProtectedBinary(true, pbData);
			if(!pb.IsProtected) throw new SecurityException("ProtectedBinary-1");

			byte[] pbDec = pb.ReadData();
			if(!MemUtil.ArraysEqual(pbData, pbDec))
				throw new SecurityException("ProtectedBinary-2");
			if(!pb.IsProtected) throw new SecurityException("ProtectedBinary-3");

			byte[] pbData2 = enc.GetBytes("Test Test Test Test");
			byte[] pbData3 = enc.GetBytes("Test Test Test Test Test");
			ProtectedBinary pb2 = new ProtectedBinary(true, pbData2);
			ProtectedBinary pb3 = new ProtectedBinary(true, pbData3);
			if(!pb.Equals(pb2)) throw new SecurityException("ProtectedBinary-4");
			if(pb.Equals(pb3)) throw new SecurityException("ProtectedBinary-5");
			if(pb2.Equals(pb3)) throw new SecurityException("ProtectedBinary-6");

			if(pb.GetHashCode() != pb2.GetHashCode())
				throw new SecurityException("ProtectedBinary-7");
			if(!((object)pb).Equals((object)pb2))
				throw new SecurityException("ProtectedBinary-8");
			if(((object)pb).Equals((object)pb3))
				throw new SecurityException("ProtectedBinary-9");
			if(((object)pb2).Equals((object)pb3))
				throw new SecurityException("ProtectedBinary-10");

			ProtectedString ps = new ProtectedString();
			if(ps.Length != 0) throw new SecurityException("ProtectedString-1");
			if(!ps.IsEmpty) throw new SecurityException("ProtectedString-2");
			if(ps.ReadString().Length != 0)
				throw new SecurityException("ProtectedString-3");

			ps = new ProtectedString(true, "Test");
			ProtectedString ps2 = new ProtectedString(true, enc.GetBytes("Test"));
			if(ps.IsEmpty) throw new SecurityException("ProtectedString-4");
			pbData = ps.ReadUtf8();
			pbData2 = ps2.ReadUtf8();
			if(!MemUtil.ArraysEqual(pbData, pbData2))
				throw new SecurityException("ProtectedString-5");
			if(pbData.Length != 4)
				throw new SecurityException("ProtectedString-6");
			if(ps.ReadString() != ps2.ReadString())
				throw new SecurityException("ProtectedString-7");
			pbData = ps.ReadUtf8();
			pbData2 = ps2.ReadUtf8();
			if(!MemUtil.ArraysEqual(pbData, pbData2))
				throw new SecurityException("ProtectedString-8");
			if(!ps.IsProtected) throw new SecurityException("ProtectedString-9");
			if(!ps2.IsProtected) throw new SecurityException("ProtectedString-10");

			Random r = new Random();
			string str = string.Empty;
			ps = new ProtectedString();
			for(int i = 0; i < 100; ++i)
			{
				bool bProt = ((r.Next() % 4) != 0);
				ps = ps.WithProtection(bProt);

				int x = r.Next(str.Length + 1);
				int c = r.Next(20);
				char ch = (char)r.Next(1, 256);

				string strIns = new string(ch, c);
				str = str.Insert(x, strIns);
				ps = ps.Insert(x, strIns);

				if(ps.IsProtected != bProt)
					throw new SecurityException("ProtectedString-11");
				if(ps.ReadString() != str)
					throw new SecurityException("ProtectedString-12");

				ps = ps.WithProtection(bProt);

				x = r.Next(str.Length);
				c = r.Next(str.Length - x + 1);

				str = str.Remove(x, c);
				ps = ps.Remove(x, c);

				if(ps.IsProtected != bProt)
					throw new SecurityException("ProtectedString-13");
				if(ps.ReadString() != str)
					throw new SecurityException("ProtectedString-14");
			}
#endif
		}
开发者ID:Stoom,项目名称:KeePass,代码行数:91,代码来源:SelfTest.cs


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