• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Security.ProtectedString类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



ProtectedString类属于KeePassLib.Security命名空间,在下文中一共展示了ProtectedString类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: ShowAndRestore

		internal static string ShowAndRestore(ProtectedString psWord,
			bool bCenterScreen, bool bSetForeground, uint uCharCount, bool? bInitHide)
		{
			IntPtr h = IntPtr.Zero;
			try { h = NativeMethods.GetForegroundWindowHandle(); }
			catch(Exception) { Debug.Assert(false); }

			CharPickerForm dlg = new CharPickerForm();
			dlg.InitEx(psWord, bCenterScreen, bSetForeground, uCharCount, bInitHide);

			DialogResult dr = dlg.ShowDialog();

			ProtectedString ps = dlg.SelectedCharacters;
			string strRet = null;
			if((dr == DialogResult.OK) && (ps != null)) strRet = ps.ReadString();

			UIUtil.DestroyForm(dlg);

			try
			{
				if(h != IntPtr.Zero)
					NativeMethods.EnsureForegroundWindow(h);
			}
			catch(Exception) { Debug.Assert(false); }

			return strRet;
		}
开发者ID:joshuadugie,项目名称:KeePass-2.x,代码行数:27,代码来源:CharPickerForm.cs


示例2: Generate

		public static PwgError Generate(out ProtectedString psOut,
			PwProfile pwProfile, byte[] pbUserEntropy,
			CustomPwGeneratorPool pwAlgorithmPool)
		{
			Debug.Assert(pwProfile != null);
			if(pwProfile == null) throw new ArgumentNullException("pwProfile");

			PwgError e = PwgError.Unknown;
			CryptoRandomStream crs = null;
			byte[] pbKey = null;
			try
			{
				crs = CreateRandomStream(pbUserEntropy, out pbKey);

				if(pwProfile.GeneratorType == PasswordGeneratorType.CharSet)
					e = CharSetBasedGenerator.Generate(out psOut, pwProfile, crs);
				else if(pwProfile.GeneratorType == PasswordGeneratorType.Pattern)
					e = PatternBasedGenerator.Generate(out psOut, pwProfile, crs);
				else if(pwProfile.GeneratorType == PasswordGeneratorType.Custom)
					e = GenerateCustom(out psOut, pwProfile, crs, pwAlgorithmPool);
				else { Debug.Assert(false); psOut = ProtectedString.Empty; }
			}
			finally
			{
				if(crs != null) crs.Dispose();
				if(pbKey != null) MemUtil.ZeroByteArray(pbKey);
			}

			return e;
		}
开发者ID:joshuadugie,项目名称:KeePass-2.x,代码行数:30,代码来源:PwGenerator.cs


示例3: 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


示例4: Generate

		public static PwgError Generate(ProtectedString psOutBuffer,
			PwProfile pwProfile, CryptoRandomStream crsRandomSource)
		{
			if(pwProfile.Length == 0) return PwgError.Success;

			PwCharSet pcs = new PwCharSet(pwProfile.CharSet.ToString());
			char[] vGenerated = new char[pwProfile.Length];

			PwGenerator.PrepareCharSet(pcs, pwProfile);

			for(int nIndex = 0; nIndex < (int)pwProfile.Length; ++nIndex)
			{
				char ch = PwGenerator.GenerateCharacter(pwProfile, pcs,
					crsRandomSource);

				if(ch == char.MinValue)
				{
					Array.Clear(vGenerated, 0, vGenerated.Length);
					return PwgError.TooFewCharacters;
				}

				vGenerated[nIndex] = ch;
			}

			byte[] pbUTF8 = Encoding.UTF8.GetBytes(vGenerated);
			psOutBuffer.SetString(Encoding.UTF8.GetString(pbUTF8, 0, pbUTF8.Length));
			Array.Clear(pbUTF8, 0, pbUTF8.Length);
			Array.Clear(vGenerated, 0, vGenerated.Length);

			return PwgError.Success;
		}
开发者ID:olivierdagenais,项目名称:testoriented,代码行数:31,代码来源:CharSetBasedGenerator.cs


示例5: Generate

        internal static PwgError Generate(out ProtectedString psOut,
			PwProfile pwProfile, CryptoRandomStream crsRandomSource)
        {
            psOut = ProtectedString.Empty;
            if(pwProfile.Length == 0) return PwgError.Success;

            PwCharSet pcs = new PwCharSet(pwProfile.CharSet.ToString());
            char[] vGenerated = new char[pwProfile.Length];

            PwGenerator.PrepareCharSet(pcs, pwProfile);

            for(int nIndex = 0; nIndex < (int)pwProfile.Length; ++nIndex)
            {
                char ch = PwGenerator.GenerateCharacter(pwProfile, pcs,
                    crsRandomSource);

                if(ch == char.MinValue)
                {
                    Array.Clear(vGenerated, 0, vGenerated.Length);
                    return PwgError.TooFewCharacters;
                }

                vGenerated[nIndex] = ch;
            }

            byte[] pbUtf8 = StrUtil.Utf8.GetBytes(vGenerated);
            psOut = new ProtectedString(true, pbUtf8);
            MemUtil.ZeroByteArray(pbUtf8);
            Array.Clear(vGenerated, 0, vGenerated.Length);

            return PwgError.Success;
        }
开发者ID:rassilon,项目名称:keepass,代码行数:32,代码来源:CharSetBasedGenerator.cs


示例6: 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


示例7: InitEx

        public void InitEx(ProtectedString psWord, bool bCenterScreen, bool bSetForeground)
        {
            m_psWord = psWord;

            if(bCenterScreen) this.StartPosition = FormStartPosition.CenterScreen;

            m_bSetForeground = bSetForeground;
        }
开发者ID:jonbws,项目名称:strengthreport,代码行数:8,代码来源:CharPickerForm.cs


示例8: SetKey

		private void SetKey(byte[] pbPasswordUtf8)
		{
			Debug.Assert(pbPasswordUtf8 != null);
			if(pbPasswordUtf8 == null) throw new ArgumentNullException("pbPasswordUtf8");

			SHA256Managed sha256 = new SHA256Managed();
			byte[] pbRaw = sha256.ComputeHash(pbPasswordUtf8);

			m_psPassword = new ProtectedString(true, pbPasswordUtf8);
			m_pbKeyData = new ProtectedBinary(true, pbRaw);
		}
开发者ID:ComradeP,项目名称:KeePass-2.x,代码行数:11,代码来源:KcpPassword.cs


示例9: InitEx

        /// <summary>
        /// Initialize the dialog. Needs to be called before the dialog is shown.
        /// </summary>
        /// <param name="vStringDict">String container. Must not be <c>null</c>.</param>
        /// <param name="strStringName">Initial name of the string. May be <c>null</c>.</param>
        /// <param name="psStringValue">Initial value. May be <c>null</c>.</param>
        public void InitEx(ProtectedStringDictionary vStringDict, string strStringName,
            ProtectedString psStringValue, PwDatabase pwContext)
        {
            Debug.Assert(vStringDict != null); if(vStringDict == null) throw new ArgumentNullException("vStringDict");
            m_vStringDict = vStringDict;

            m_strStringName = strStringName;
            m_psStringValue = psStringValue;

            m_pwContext = pwContext;
        }
开发者ID:jonbws,项目名称:strengthreport,代码行数:17,代码来源:EditStringForm.cs


示例10: GetKeyParts

		internal static ProtectedString GetKeyParts(byte[] pbPasswordUtf8, out ProtectedBinary pbKeyData)
		{
			Debug.Assert(pbPasswordUtf8 != null);
			if(pbPasswordUtf8 == null) throw new ArgumentNullException("pbPasswordUtf8");

			SHA256Managed sha256 = new SHA256Managed();
			byte[] pbRaw = sha256.ComputeHash(pbPasswordUtf8);

			var psPassword = new ProtectedString(true, pbPasswordUtf8);
			pbKeyData = new ProtectedBinary(true, pbRaw);
			return psPassword;
		}
开发者ID:olivierdagenais,项目名称:testoriented,代码行数:12,代码来源:KcpPassword.cs


示例11: SetKey

		private void SetKey(byte[] pbPasswordUtf8)
		{
			Debug.Assert(pbPasswordUtf8 != null);
			if(pbPasswordUtf8 == null) throw new ArgumentNullException("pbPasswordUtf8");

#if (DEBUG && !KeePassLibSD)
			Debug.Assert(ValidatePassword(pbPasswordUtf8));
#endif

			byte[] pbRaw = CryptoUtil.HashSha256(pbPasswordUtf8);

			m_psPassword = new ProtectedString(true, pbPasswordUtf8);
			m_pbKeyData = new ProtectedBinary(true, pbRaw);
		}
开发者ID:joshuadugie,项目名称:KeePass-2.x,代码行数:14,代码来源:KcpPassword.cs


示例12: 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


示例13: Generate

		public static PwgError Generate(ProtectedString psOutBuffer,
			PwProfile pwProfile, byte[] pbUserEntropy,
			CustomPwGeneratorPool pwAlgorithmPool)
		{
			Debug.Assert(psOutBuffer != null);
			if(psOutBuffer == null) throw new ArgumentNullException("psOutBuffer");
			Debug.Assert(pwProfile != null);
			if(pwProfile == null) throw new ArgumentNullException("pwProfile");

			psOutBuffer.Clear();

			CryptoRandomStream crs = CreateCryptoStream(pbUserEntropy);
			PwgError e = PwgError.Unknown;

			if(pwProfile.GeneratorType == PasswordGeneratorType.CharSet)
				e = CharSetBasedGenerator.Generate(psOutBuffer, pwProfile, crs);
			else if(pwProfile.GeneratorType == PasswordGeneratorType.Pattern)
				e = PatternBasedGenerator.Generate(psOutBuffer, pwProfile, crs);
			else if(pwProfile.GeneratorType == PasswordGeneratorType.Custom)
				e = GenerateCustom(psOutBuffer, pwProfile, crs, pwAlgorithmPool);
			else { Debug.Assert(false); }

			return e;
		}
开发者ID:olivierdagenais,项目名称:testoriented,代码行数:24,代码来源:PwGenerator.cs


示例14: OnBtnOK

 private void OnBtnOK(object sender, EventArgs e)
 {
     byte[] pbUtf8 = m_secWord.ToUtf8();
     m_psSelected = new ProtectedString(true, pbUtf8);
     Array.Clear(pbUtf8, 0, pbUtf8.Length);
 }
开发者ID:earthday,项目名称:keepass2,代码行数:6,代码来源:CharPickerForm.cs


示例15: Remove

		public ProtectedString Remove(int iStart, int nCount)
		{
			if(iStart < 0) throw new ArgumentOutOfRangeException("iStart");
			if(nCount < 0) throw new ArgumentOutOfRangeException("nCount");
			if(nCount == 0) return this;

			// Only operate directly with strings when m_bIsProtected is
			// false, not in the case of non-null m_strPlainText, because
			// the operation creates a new sequence in memory
			if(!m_bIsProtected)
				return new ProtectedString(false, ReadString().Remove(
					iStart, nCount));

			UTF8Encoding utf8 = StrUtil.Utf8;

			byte[] pb = ReadUtf8();
			char[] v = utf8.GetChars(pb);
			char[] vNew;

			try
			{
				if((iStart + nCount) > v.Length)
					throw new ArgumentException("iStart + nCount");

				vNew = new char[v.Length - nCount];
				Array.Copy(v, 0, vNew, 0, iStart);
				Array.Copy(v, iStart + nCount, vNew, iStart, v.Length -
					(iStart + nCount));
			}
			finally
			{
				Array.Clear(v, 0, v.Length);
				MemUtil.ZeroByteArray(pb);
			}

			byte[] pbNew = utf8.GetBytes(vNew);
			ProtectedString ps = new ProtectedString(m_bIsProtected, pbNew);

			Debug.Assert(utf8.GetString(pbNew, 0, pbNew.Length) ==
				ReadString().Remove(iStart, nCount));

			Array.Clear(vNew, 0, vNew.Length);
			MemUtil.ZeroByteArray(pbNew);
			return ps;
		}
开发者ID:riking,项目名称:go-keepass2,代码行数:45,代码来源:ProtectedString.cs


示例16: WithProtection

		public ProtectedString WithProtection(bool bProtect)
		{
			if(bProtect == m_bIsProtected) return this;

			byte[] pb = ReadUtf8();
			ProtectedString ps = new ProtectedString(bProtect, pb);

			if(bProtect) MemUtil.ZeroByteArray(pb);
			return ps;
		}
开发者ID:riking,项目名称:go-keepass2,代码行数:10,代码来源:ProtectedString.cs


示例17: 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


示例18: ReplaceNewPasswordPlaceholder

        private static string ReplaceNewPasswordPlaceholder(string strText,
            SprContext ctx, uint uRecursionLevel)
        {
            PwEntry pe = ctx.Entry;
            PwDatabase pd = ctx.Database;
            if((pe == null) || (pd == null)) return strText;

            string str = strText;

            const string strNewPwStart = @"{NEWPASSWORD";
            if(str.IndexOf(strNewPwStart, StrUtil.CaseIgnoreCmp) < 0) return str;

            string strGen = null;

            int iStart;
            List<string> lParams;
            while(SprEngine.ParseAndRemovePlhWithParams(ref str, ctx, uRecursionLevel,
                strNewPwStart + ":", out iStart, out lParams, true))
            {
                if(strGen == null)
                    strGen = GeneratePassword((((lParams != null) &&
                        (lParams.Count > 0)) ? lParams[0] : string.Empty), ctx);

                str = str.Insert(iStart, strGen);
            }

            const string strNewPwPlh = strNewPwStart + @"}";
            if(str.IndexOf(strNewPwPlh, StrUtil.CaseIgnoreCmp) >= 0)
            {
                if(strGen == null) strGen = GeneratePassword(null, ctx);

                str = StrUtil.ReplaceCaseInsensitive(str, strNewPwPlh, strGen);
            }

            if(strGen != null)
            {
                pe.CreateBackup(pd);

                ProtectedString psGen = new ProtectedString(
                    pd.MemoryProtection.ProtectPassword, strGen);
                pe.Strings.Set(PwDefs.PasswordField, psGen);

                pe.Touch(true, false);
                pd.Modified = true;
            }
            else { Debug.Assert(false); }

            return str;
        }
开发者ID:rdealexb,项目名称:keepass,代码行数:49,代码来源:EntryUtil.cs


示例19: InitEx

        /// <summary>
        /// Initialize the dialog.
        /// </summary>
        /// <param name="psWord">Password to pick characters from.</param>
        /// <param name="bCenterScreen">Specifies whether to center the form
        /// on the screen or not.</param>
        /// <param name="bSetForeground">If <c>true</c>, the window will be
        /// brought to the foreground when showing it.</param>
        /// <param name="uCharCount">Number of characters to pick. Specify
        /// 0 to allow picking a variable amount of characters.</param>
        public void InitEx(ProtectedString psWord, bool bCenterScreen,
            bool bSetForeground, uint uCharCount, bool? bInitHide)
        {
            m_psWord = psWord;

            if(bCenterScreen) this.StartPosition = FormStartPosition.CenterScreen;

            m_bSetForeground = bSetForeground;
            m_uCharCount = uCharCount;
            m_bInitHide = bInitHide;
        }
开发者ID:earthday,项目名称:keepass2,代码行数:21,代码来源:CharPickerForm.cs


示例20: 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



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Utility.CharStream类代码示例发布时间:2022-05-26
下一篇:
C# Security.ProtectedBinary类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap