本文整理汇总了C#中KeePassLib.Security.ProtectedString.Remove方法的典型用法代码示例。如果您正苦于以下问题:C# ProtectedString.Remove方法的具体用法?C# ProtectedString.Remove怎么用?C# ProtectedString.Remove使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类KeePassLib.Security.ProtectedString
的用法示例。
在下文中一共展示了ProtectedString.Remove方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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
}