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


C# PasswordGenerator.PwProfile类代码示例

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


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

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

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

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

示例4: CompareProfilesByName

        public static int CompareProfilesByName(PwProfile a, PwProfile b)
        {
            if(a == b) return 0;
            if(a == null) { Debug.Assert(false); return -1; }
            if(b == null) { Debug.Assert(false); return 1; }

            return StrUtil.CompareNaturally(a.Name, b.Name);
        }
开发者ID:haro-freezd,项目名称:KeePass,代码行数:8,代码来源:PwGeneratorUtil.cs

示例5: CollectEntropyIfEnabled

		public static byte[] CollectEntropyIfEnabled(PwProfile pp)
		{
			if(pp.CollectUserEntropy == false) return null;

			EntropyForm ef = new EntropyForm();
			if(ef.ShowDialog() == DialogResult.OK)
				return ef.GeneratedEntropy;

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

示例6: InitEx

		/// <summary>
		/// Initialize this password generator form instance.
		/// </summary>
		/// <param name="pwInitial">Initial options (may be <c>null</c>).</param>
		public void InitEx(PwProfile pwInitial, bool bCanAccept, bool bForceInTaskbar)
		{
			m_optInitial = pwInitial;
			m_bCanAccept = bCanAccept;

			// m_bForceInTaskbar = bForceInTaskbar;
			// Set ShowInTaskbar immediately, not later, otherwise the form
			// can disappear:
			// https://sourceforge.net/p/keepass/discussion/329220/thread/c95b5644/
			if(bForceInTaskbar) this.ShowInTaskbar = true;
		}
开发者ID:riking,项目名称:go-keepass2,代码行数:15,代码来源:PwGeneratorForm.cs

示例7: AddStdPattern

        private static void AddStdPattern(string strName, string strPattern)
        {
            PwProfile p = new PwProfile();

            p.Name = strName;
            p.CollectUserEntropy = false;
            p.GeneratorType = PasswordGeneratorType.Pattern;
            p.Pattern = strPattern;

            Program.Config.PasswordGenerator.UserProfiles.Add(p);
        }
开发者ID:elitak,项目名称:keepass,代码行数:11,代码来源:PwGeneratorUtil.cs

示例8: CollectEntropyIfEnabled

        public static byte[] CollectEntropyIfEnabled(PwProfile pp)
        {
            if(!pp.CollectUserEntropy) return null;

            EntropyForm ef = new EntropyForm();
            if(UIUtil.ShowDialogNotValue(ef, DialogResult.OK)) return null;

            byte[] pbGen = ef.GeneratedEntropy;
            UIUtil.DestroyForm(ef);
            return pbGen;
        }
开发者ID:earthday,项目名称:keepass2,代码行数:11,代码来源:EntropyForm.cs

示例9: AddStdPattern

		private static void AddStdPattern(string strName, string strPattern)
		{
			PwProfile p = new PwProfile();

			p.Name = strName + PwGeneratorUtil.BuiltInSuffix;
			p.CollectUserEntropy = false;
			p.GeneratorType = PasswordGeneratorType.Pattern;
			p.Pattern = strPattern;

			m_lBuiltIn.Add(p);
		}
开发者ID:riking,项目名称:go-keepass2,代码行数:11,代码来源:PwGeneratorUtil.cs

示例10: Generate

 public override ProtectedString Generate(PwProfile prf, CryptoRandomStream crsRandomSource)
 {
     if (prf == null) { Debug.Assert(false); }
     else
     {
         Debug.Assert(prf.CustomAlgorithmUuid == Convert.ToBase64String(
             m_uuid.UuidBytes, Base64FormattingOptions.None));
     }
     Random keylen = new Random((int)crsRandomSource.GetRandomUInt64());
     int k = keylen.Next(3, 7);
     return new ProtectedString(false, cockPwdGenerator(k,keylen));
 }
开发者ID:ifooth,项目名称:Cockroach,代码行数:12,代码来源:CockroachGen.cs

示例11: Generate

        public override ProtectedString Generate(PwProfile prf, CryptoRandomStream crsRandomSource)
        {
            if (prf == null)
                Debug.Assert(false);
            else
                Debug.Assert(prf.CustomAlgorithmUuid == Convert.ToBase64String(m_uuid.UuidBytes, Base64FormattingOptions.None));

            if (string.IsNullOrEmpty(settings.WordListLocation))
            {
                System.Windows.Forms.MessageBox.Show("No word list location");
                GetSettingsFromUser();
                return null;
            }

            if (!System.IO.File.Exists(settings.WordListLocation))
            {
                System.Windows.Forms.MessageBox.Show(string.Format("Word List doesn't exist at location {0}", settings.WordListLocation));
                GetSettingsFromUser();
                return null;
            }

            try
            {
                if (words == null)
                    words = System.IO.File.ReadAllLines(settings.WordListLocation);

                StringBuilder sb = new StringBuilder();
                for (int i = 0; i < settings.NumberOfWords; i++)
                {
                    ulong u = crsRandomSource.GetRandomUInt64();
                    u %= (ulong)(words.Length - 1);

                    if (i > 0) sb.Append(settings.Separator);

                    string word = words[u];
                    if (i == 0 && word.Length > 1)
                        word = word.Substring(0, 1).ToUpper() + word.Substring(1, word.Length - 1);

                    sb.Append(word);
                }
                sb.Append(settings.TrailingTrash);
                return new ProtectedString(false, sb.ToString());
            }

            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(string.Format("Encountered this error while generating password: {0}", ex.Message));
            }
            return null;
        }
开发者ID:sideproject,项目名称:KeePass_PassPhraseGenerator,代码行数:50,代码来源:PassPhraseGenerator.cs

示例12: GenerateCharacter

		internal static char GenerateCharacter(PwProfile pwProfile,
			PwCharSet pwCharSet, CryptoRandomStream crsRandomSource)
		{
			if(pwCharSet.Size == 0) return char.MinValue;

			ulong uIndex = crsRandomSource.GetRandomUInt64();
			uIndex %= (ulong)pwCharSet.Size;

			char ch = pwCharSet[(uint)uIndex];

			if(pwProfile.NoRepeatingCharacters)
				pwCharSet.Remove(ch);

			return ch;
		}
开发者ID:riking,项目名称:go-keepass2,代码行数:15,代码来源:PwGenerator.cs

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

示例14: Generate

        public override ProtectedString Generate(PwProfile prf, CryptoRandomStream crsRandomSource)
        {
            Random r = new Random((int)crsRandomSource.GetRandomUInt64());
            var opt = new DiceWareOptions(prf.CustomAlgorithmOptions);

            string result = "";
            int word = 0;

            for (int i = 0; i < 5 * opt.WordCount; i++)
            {
                word *= 10;
                word += (1 + r.Next(6));

                if ((i + 1) % 5 == 0 && i > 0)
                {
                    result += words[word];
                    result += " ";

                    word = 0;
                }
            }

            return new ProtectedString(true, result.Trim());
        }
开发者ID:rodoviario,项目名称:diceware-1,代码行数:24,代码来源:DiceWarePwGen.cs

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


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