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


C# PasswordDeriveBytes.Reset方法代码示例

本文整理汇总了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;
	}
开发者ID:Profit0004,项目名称:mono,代码行数:55,代码来源:PasswordDeriveBytesTest.cs

示例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");
	}
开发者ID:Profit0004,项目名称:mono,代码行数:13,代码来源:PasswordDeriveBytesTest.cs

示例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 ();
		}
	}
开发者ID:Profit0004,项目名称:mono,代码行数:17,代码来源:PasswordDeriveBytesTest.cs


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