本文整理汇总了C#中System.Security.Cryptography.PasswordDeriveBytes.Reset方法的典型用法代码示例。如果您正苦于以下问题:C# PasswordDeriveBytes.Reset方法的具体用法?C# PasswordDeriveBytes.Reset怎么用?C# PasswordDeriveBytes.Reset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Security.Cryptography.PasswordDeriveBytes
的用法示例。
在下文中一共展示了PasswordDeriveBytes.Reset方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Properties
public void Properties ()
{
// create object...
PasswordDeriveBytes pd = new PasswordDeriveBytes ("password", null, "MD5", 1000);
Assert.AreEqual ("MD5", pd.HashName, "HashName-MD5");
Assert.AreEqual (1000, pd.IterationCount, "IterationCount-1000");
// ...then change all its properties...
pd.HashName = "SHA1";
Assert.AreEqual ("SHA1", pd.HashName, "HashName-SHA1");
pd.Salt = salt;
Assert.AreEqual (ssalt, BitConverter.ToString (pd.Salt), "Salt");
pd.IterationCount = 1;
Assert.AreEqual (1, pd.IterationCount, "IterationCount-1");
byte[] expectedKey = { 0x0b, 0x61, 0x93, 0x96 };
// ... before using it
Assert.AreEqual (expectedKey, pd.GetBytes (4), "PKCS#5 test properties");
// it should work but if we try to set any properties after GetBytes
// they should all throw an exception
try {
pd.HashName = "SHA256";
Assert.Fail ("PKCS#5 can't set HashName after GetBytes - expected CryptographicException but got none");
}
catch (CryptographicException) {
// do nothing, this is what we expect
}
catch (Exception e) {
Assert.Fail ("PKCS#5 can't set HashName after GetBytes - expected CryptographicException but got " + e.ToString ());
}
try {
pd.Salt = expectedKey;
Assert.Fail ("PKCS#5 can't set Salt after GetBytes - expected CryptographicException but got none");
}
catch (CryptographicException) {
// do nothing, this is what we expect
}
catch (Exception e) {
Assert.Fail ("PKCS#5 can't set Salt after GetBytes - expected CryptographicException but got " + e.ToString ());
}
try {
pd.IterationCount = 10;
Assert.Fail ("PKCS#5 can't set IterationCount after GetBytes - expected CryptographicException but got none");
}
catch (CryptographicException) {
// do nothing, this is what we expect
}
catch (Exception e) {
Assert.Fail ("PKCS#5 can't set IterationCount after GetBytes - expected CryptographicException but got " + e.ToString ());
}
pd.Reset ();
// finally a useful reset :)
pd.HashName = "SHA256";
pd.Salt = expectedKey;
pd.IterationCount = 10;
}
示例2: LongMultipleGetBytes
[Category ("NotWorking")] // bug #79499
public void LongMultipleGetBytes ()
{
// based on http://bugzilla.ximian.com/show_bug.cgi?id=79499
PasswordDeriveBytes pd = new PasswordDeriveBytes ("mono", new byte[20]);
string key = BitConverter.ToString (pd.GetBytes (32));
Assert.AreEqual ("88-0A-AE-0A-41-61-02-78-FD-E2-70-9F-25-13-14-28-1F-C7-D9-72-9A-AE-CA-3F-BD-31-B4-F0-BD-8E-5B-98", key, "key");
string iv = BitConverter.ToString (pd.GetBytes (16));
Assert.AreEqual ("FD-E2-70-9F-25-13-14-28-4D-3F-9B-F8-EE-AA-95-ED", iv, "iv");
pd.Reset ();
// bytes from 32-40 are different from calling GetBytes separately
Assert.AreEqual (key + "-F6-55-6C-3E-54-8B-F3-73-4D-3F-9B-F8-EE-AA-95-ED", BitConverter.ToString (pd.GetBytes (48)), "same");
}
示例3: ShortRun
// generate the key up to HashSize and reset between operations
public void ShortRun(string msg, PasswordDeriveBytes pd, byte[] finalKey)
{
for (int i=0; i < finalKey.Length; i++) {
int j = 0;
bool compare = true;
byte[] key = pd.GetBytes (i+1);
for (; j < i; j++) {
if (finalKey [j] != key[j]) {
compare = false;
break;
}
}
Assert.IsTrue (compare, msg + " #" + j);
pd.Reset ();
}
}