本文整理汇总了C#中KeePassLib.Security.ProtectedString.ReadUtf8方法的典型用法代码示例。如果您正苦于以下问题:C# ProtectedString.ReadUtf8方法的具体用法?C# ProtectedString.ReadUtf8怎么用?C# ProtectedString.ReadUtf8使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类KeePassLib.Security.ProtectedString
的用法示例。
在下文中一共展示了ProtectedString.ReadUtf8方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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
}
示例2: 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
}
示例3: OnProfilesDynamicMenuClick
private void OnProfilesDynamicMenuClick(object sender, DynamicMenuEventArgs e)
{
PwProfile pwp = null;
if(e.ItemName == DeriveFromPrevious)
{
byte[] pbCur = m_secPassword.ToUtf8();
ProtectedString psCur = new ProtectedString(true, pbCur);
Array.Clear(pbCur, 0, pbCur.Length);
pwp = PwProfile.DeriveFromPassword(psCur);
}
else
{
foreach(PwProfile pwgo in Program.Config.PasswordGenerator.UserProfiles)
{
if(pwgo.Name == e.ItemName)
{
pwp = pwgo;
break;
}
}
}
if(pwp != null)
{
ProtectedString psNew = new ProtectedString(true);
PwGenerator.Generate(psNew, pwp, null, Program.PwGeneratorPool);
byte[] pbNew = psNew.ReadUtf8();
m_secPassword.SetPassword(pbNew);
m_secRepeat.SetPassword(pbNew);
Array.Clear(pbNew, 0, pbNew.Length);
}
else { Debug.Assert(false); }
}
示例4: OnPwGenOpen
private void OnPwGenOpen(object sender, EventArgs e)
{
PwGeneratorForm pgf = new PwGeneratorForm();
byte[] pbCurPassword = m_secPassword.ToUtf8();
bool bAtLeastOneChar = (pbCurPassword.Length > 0);
ProtectedString ps = new ProtectedString(true, pbCurPassword);
Array.Clear(pbCurPassword, 0, pbCurPassword.Length);
PwProfile opt = PwProfile.DeriveFromPassword(ps);
pgf.InitEx(bAtLeastOneChar ? opt : null, true, false);
// pgf.InitEx(null, true, false);
if(pgf.ShowDialog() == DialogResult.OK)
{
byte[] pbEntropy = EntropyForm.CollectEntropyIfEnabled(pgf.SelectedProfile);
ProtectedString psNew = new ProtectedString(true);
PwGenerator.Generate(psNew, pgf.SelectedProfile, pbEntropy,
Program.PwGeneratorPool);
byte[] pbNew = psNew.ReadUtf8();
m_secPassword.SetPassword(pbNew);
m_secRepeat.SetPassword(pbNew);
Array.Clear(pbNew, 0, pbNew.Length);
}
UIUtil.DestroyForm(pgf);
EnableControlsEx();
}
示例5: DeriveFromPassword
public static PwProfile DeriveFromPassword(ProtectedString psPassword)
{
PwProfile pp = new PwProfile();
Debug.Assert(psPassword != null); if(psPassword == null) return pp;
PwCharSet pcs = pp.CharSet;
byte[] pbUTF8 = psPassword.ReadUtf8();
char[] vChars = Encoding.UTF8.GetChars(pbUTF8);
pp.GeneratorType = PasswordGeneratorType.CharSet;
pp.Length = (uint)vChars.Length;
foreach(char ch in vChars)
{
if((ch >= 'A') && (ch <= 'Z')) pcs.Add(PwCharSet.UpperCase);
else if((ch >= 'a') && (ch <= 'z')) pcs.Add(PwCharSet.LowerCase);
else if((ch >= '0') && (ch <= '9')) pcs.Add(PwCharSet.Digits);
else if((@"!#$%&'*+,./:;[email protected]^").IndexOf(ch) >= 0) pcs.Add(pcs.SpecialChars);
else if(ch == ' ') pcs.Add(' ');
else if(ch == '-') pcs.Add('-');
else if(ch == '_') pcs.Add('_');
else if(ch == '\"') pcs.Add(pcs.SpecialChars);
else if(ch == '\\') pcs.Add(pcs.SpecialChars);
else if((@"()[]{}<>").IndexOf(ch) >= 0) pcs.Add(PwCharSet.Brackets);
else if((ch >= '~') && (ch <= 255)) pcs.Add(pcs.HighAnsiChars);
else pcs.Add(ch);
}
Array.Clear(vChars, 0, vChars.Length);
Array.Clear(pbUTF8, 0, pbUTF8.Length);
return pp;
}