本文整理汇总了C#中KeePassLib.Cryptography.PasswordGenerator.PwProfile类的典型用法代码示例。如果您正苦于以下问题:C# PwProfile类的具体用法?C# PwProfile怎么用?C# PwProfile使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PwProfile类属于KeePassLib.Cryptography.PasswordGenerator命名空间,在下文中一共展示了PwProfile类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: OnFileNew
//.........这里部分代码省略.........
pg = new PwGroup(true, true, KPRes.Internet, PwIcon.World);
// pg.CustomData.Set("GroupTestItem", "TestValue");
pd.RootGroup.AddGroup(pg, true);
pg = new PwGroup(true, true, KPRes.EMail, PwIcon.EMail);
pd.RootGroup.AddGroup(pg, true);
pg = new PwGroup(true, true, KPRes.Homebanking, PwIcon.Homebanking);
pd.RootGroup.AddGroup(pg, true);
PwEntry pe = new PwEntry(true, true);
pe.Strings.Set(PwDefs.TitleField, new ProtectedString(pd.MemoryProtection.ProtectTitle,
KPRes.SampleEntry));
pe.Strings.Set(PwDefs.UserNameField, new ProtectedString(pd.MemoryProtection.ProtectUserName,
KPRes.UserName));
pe.Strings.Set(PwDefs.UrlField, new ProtectedString(pd.MemoryProtection.ProtectUrl,
PwDefs.HomepageUrl));
pe.Strings.Set(PwDefs.PasswordField, new ProtectedString(pd.MemoryProtection.ProtectPassword,
KPRes.Password));
pe.Strings.Set(PwDefs.NotesField, new ProtectedString(pd.MemoryProtection.ProtectNotes,
KPRes.Notes));
pe.AutoType.Add(new AutoTypeAssociation(KPRes.TargetWindow,
@"{USERNAME}{TAB}{PASSWORD}{TAB}{ENTER}"));
// for(int i = 0; i < 30; ++i) pe.CustomData.Set("Test" + i.ToString("D2"), "12345");
pd.RootGroup.AddEntry(pe, true);
pe = new PwEntry(true, true);
pe.Strings.Set(PwDefs.TitleField, new ProtectedString(pd.MemoryProtection.ProtectTitle,
KPRes.SampleEntry + " #2"));
pe.Strings.Set(PwDefs.UserNameField, new ProtectedString(pd.MemoryProtection.ProtectUserName,
"Michael321"));
pe.Strings.Set(PwDefs.UrlField, new ProtectedString(pd.MemoryProtection.ProtectUrl,
@"http://keepass.info/help/kb/testform.html"));
pe.Strings.Set(PwDefs.PasswordField, new ProtectedString(pd.MemoryProtection.ProtectPassword,
"12345"));
pe.AutoType.Add(new AutoTypeAssociation("*Test Form - KeePass*", string.Empty));
pd.RootGroup.AddEntry(pe, true);
#if DEBUG
Random r = Program.GlobalRandom;
long lTimeMin = (new DateTime(2000, 1, 1, 0, 0, 0, DateTimeKind.Utc)).ToBinary();
long lTimeMax = (new DateTime(2030, 11, 25, 11, 58, 58, DateTimeKind.Utc)).ToBinary();
Debug.Assert(lTimeMin < lTimeMax);
PwProfile prf = new PwProfile();
prf.CharSet = new PwCharSet(PwCharSet.UpperCase + PwCharSet.LowerCase +
PwCharSet.Digits + PwCharSet.PrintableAsciiSpecial);
prf.GeneratorType = PasswordGeneratorType.CharSet;
for(uint iSamples = 0; iSamples < 1500; ++iSamples)
{
pg = pd.RootGroup.Groups.GetAt(iSamples % 5);
pe = new PwEntry(true, true);
ProtectedString ps;
PwGenerator.Generate(out ps, prf, null, null);
pe.Strings.Set(PwDefs.TitleField, new ProtectedString(pd.MemoryProtection.ProtectTitle,
ps.ReadString()));
PwGenerator.Generate(out ps, prf, null, null);
pe.Strings.Set(PwDefs.UserNameField, new ProtectedString(pd.MemoryProtection.ProtectUserName,
ps.ReadString()));
PwGenerator.Generate(out ps, prf, null, null);
pe.Strings.Set(PwDefs.UrlField, new ProtectedString(pd.MemoryProtection.ProtectUrl,
ps.ReadString()));
PwGenerator.Generate(out ps, prf, null, null);
pe.Strings.Set(PwDefs.PasswordField, new ProtectedString(pd.MemoryProtection.ProtectPassword,
ps.ReadString()));
PwGenerator.Generate(out ps, prf, null, null);
pe.Strings.Set(PwDefs.NotesField, new ProtectedString(pd.MemoryProtection.ProtectNotes,
ps.ReadString()));
pe.CreationTime = DateTime.FromBinary(lTimeMin + (long)(r.NextDouble() *
(lTimeMax - lTimeMin)));
pe.LastModificationTime = DateTime.FromBinary(lTimeMin + (long)(r.NextDouble() *
(lTimeMax - lTimeMin)));
pe.LastAccessTime = DateTime.FromBinary(lTimeMin + (long)(r.NextDouble() *
(lTimeMax - lTimeMin)));
pe.ExpiryTime = DateTime.FromBinary(lTimeMin + (long)(r.NextDouble() *
(lTimeMax - lTimeMin)));
pe.LocationChanged = DateTime.FromBinary(lTimeMin + (long)(r.NextDouble() *
(lTimeMax - lTimeMin)));
pe.IconId = (PwIcon)r.Next(0, (int)PwIcon.Count);
pg.AddEntry(pe, true);
}
pd.CustomData.Set("Sample Custom Data 1", "0123456789");
pd.CustomData.Set("Sample Custom Data 2", "\u00B5y data");
// pd.PublicCustomData.SetString("Sample Custom Data", "Sample Value");
#endif
UpdateUI(true, null, true, null, true, null, true);
if(this.FileCreated != null)
{
FileCreatedEventArgs ea = new FileCreatedEventArgs(pd);
this.FileCreated(this, ea);
}
}
开发者ID:joshuadugie,项目名称:KeePass-2.x,代码行数:101,代码来源:MainForm.cs
示例17: GetGenerationOptions
private PwProfile GetGenerationOptions()
{
PwProfile opt = new PwProfile();
opt.Name = m_cmbProfiles.Text;
if(m_rbStandardCharSet.Checked)
opt.GeneratorType = PasswordGeneratorType.CharSet;
else if(m_rbPattern.Checked)
opt.GeneratorType = PasswordGeneratorType.Pattern;
else if(m_rbCustom.Checked)
opt.GeneratorType = PasswordGeneratorType.Custom;
opt.Length = (uint)m_numGenChars.Value;
opt.CharSet = new PwCharSet();
if(m_cbUpperCase.Checked) opt.CharSet.Add(PwCharSet.UpperCase);
if(m_cbLowerCase.Checked) opt.CharSet.Add(PwCharSet.LowerCase);
if(m_cbDigits.Checked) opt.CharSet.Add(PwCharSet.Digits);
if(m_cbSpecial.Checked) opt.CharSet.Add(PwCharSet.SpecialChars);
if(m_cbHighAnsi.Checked) opt.CharSet.Add(PwCharSet.HighAnsiChars);
if(m_cbMinus.Checked) opt.CharSet.Add('-');
if(m_cbUnderline.Checked) opt.CharSet.Add('_');
if(m_cbSpace.Checked) opt.CharSet.Add(' ');
if(m_cbBrackets.Checked) opt.CharSet.Add(PwCharSet.Brackets);
opt.CharSet.Add(m_tbCustomChars.Text);
opt.Pattern = m_tbPattern.Text;
opt.PatternPermutePassword = m_cbPatternPermute.Checked;
opt.CollectUserEntropy = m_cbEntropy.Checked;
opt.ExcludeLookAlike = m_cbExcludeLookAlike.Checked;
opt.NoRepeatingCharacters = m_cbNoRepeat.Checked;
opt.ExcludeCharacters = m_tbExcludeChars.Text;
CustomPwGenerator pwg = GetPwGenerator();
opt.CustomAlgorithmUuid = ((pwg != null) ? Convert.ToBase64String(
pwg.Uuid.UuidBytes) : string.Empty);
if((pwg != null) && m_dictCustomOptions.ContainsKey(pwg))
opt.CustomAlgorithmOptions = (m_dictCustomOptions[pwg] ?? string.Empty);
else opt.CustomAlgorithmOptions = string.Empty;
return opt;
}
开发者ID:haro-freezd,项目名称:KeePass,代码行数:46,代码来源:PwGeneratorForm.cs
示例18: PrepareCharSet
internal static void PrepareCharSet(PwCharSet pwCharSet, PwProfile pwProfile)
{
pwCharSet.Remove(PwCharSet.Invalid);
if(pwProfile.ExcludeLookAlike) pwCharSet.Remove(PwCharSet.LookAlike);
if(pwProfile.ExcludeCharacters.Length > 0)
pwCharSet.Remove(pwProfile.ExcludeCharacters);
}
开发者ID:riking,项目名称:go-keepass2,代码行数:9,代码来源:PwGenerator.cs
示例19: 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;
}
开发者ID:eis,项目名称:keepass-eis-flavored,代码行数:10,代码来源:PwGeneratorForm.cs
示例20: GenerateCustom
private static PwgError GenerateCustom(out ProtectedString psOut,
PwProfile pwProfile, CryptoRandomStream crs,
CustomPwGeneratorPool pwAlgorithmPool)
{
psOut = ProtectedString.Empty;
Debug.Assert(pwProfile.GeneratorType == PasswordGeneratorType.Custom);
if(pwAlgorithmPool == null) return PwgError.UnknownAlgorithm;
string strID = pwProfile.CustomAlgorithmUuid;
if(string.IsNullOrEmpty(strID)) { Debug.Assert(false); return PwgError.UnknownAlgorithm; }
byte[] pbUuid = Convert.FromBase64String(strID);
PwUuid uuid = new PwUuid(pbUuid);
CustomPwGenerator pwg = pwAlgorithmPool.Find(uuid);
if(pwg == null) { Debug.Assert(false); return PwgError.UnknownAlgorithm; }
ProtectedString pwd = pwg.Generate(pwProfile.CloneDeep(), crs);
if(pwd == null) return PwgError.Unknown;
psOut = pwd;
return PwgError.Success;
}
开发者ID:riking,项目名称:go-keepass2,代码行数:23,代码来源:PwGenerator.cs
注:本文中的KeePassLib.Cryptography.PasswordGenerator.PwProfile类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论