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


C# DSACryptoServiceProvider.CreateSignature方法代码示例

本文整理汇总了C#中System.Security.Cryptography.DSACryptoServiceProvider.CreateSignature方法的典型用法代码示例。如果您正苦于以下问题:C# DSACryptoServiceProvider.CreateSignature方法的具体用法?C# DSACryptoServiceProvider.CreateSignature怎么用?C# DSACryptoServiceProvider.CreateSignature使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Security.Cryptography.DSACryptoServiceProvider的用法示例。


在下文中一共展示了DSACryptoServiceProvider.CreateSignature方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: LimitedKeyGeneration

	public void LimitedKeyGeneration () 
	{
		// Test smallest valid key size (performance issue)
		using (dsa = new DSACryptoServiceProvider (minKeySize)) {	// MS generates keypair here
			Assert.AreEqual (minKeySize, dsa.KeySize, "BeforeMonoKeyGeneration.KeySize");
			byte[] hash = new byte [20];
			dsa.CreateSignature (hash);				// mono generates keypair here
			Assert.AreEqual (minKeySize, dsa.KeySize, "AfterMonoKeyGeneration.KeySize");
			Assert.IsFalse (dsa.PublicOnly, "PublicOnly");
		}
		// here Dispose is called (with true)
	}
开发者ID:carrie901,项目名称:mono,代码行数:12,代码来源:DSACryptoServiceProviderTest.cs

示例2: SignAndVerify

	private void SignAndVerify (string msg, DSACryptoServiceProvider dsa)
	{
		byte[] hash = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13 };
		byte[] sign1 = dsa.CreateSignature (hash);
		byte[] sign2 = dsa.SignData (hash, 0, hash.Length);
		byte[] sign3 = dsa.SignData (new MemoryStream (hash));

		// we don't need the private key to verify
		DSAParameters param = dsa.ExportParameters (false);
		DSACryptoServiceProvider key = (DSACryptoServiceProvider) DSA.Create ();
		key.ImportParameters (param);
		// the signature is never the same so the only way to know if 
		// it worked is to verify it ourselve (i.e. can't compare)
		bool ok = key.VerifySignature (hash, sign1);
		Assert.IsTrue (ok, msg + "-CreateSignature-VerifySignature");

		ok = key.VerifyHash (hash, null, sign1);
		Assert.IsTrue (ok, msg + "-CreateSignature-VerifyHash");

		ok = key.VerifyData (hash, sign2);
		Assert.IsTrue (ok, msg + "-SignData(byte[])-VerifyData");

		ok = key.VerifyData (hash, sign3);
		Assert.IsTrue (ok, msg + "-SignData(Stream)-VerifyData");
	}
开发者ID:carrie901,项目名称:mono,代码行数:25,代码来源:DSACryptoServiceProviderTest.cs

示例3: LimitedKeyGeneration

	public void LimitedKeyGeneration () 
	{
		// Test smallest valid key size (performance issue)
		using (dsa = new DSACryptoServiceProvider (minKeySize)) {	// MS generates keypair here
			AssertEquals ("BeforeMonoKeyGeneration.KeySize", minKeySize, dsa.KeySize);
			byte[] hash = new byte [20];
			dsa.CreateSignature (hash);				// mono generates keypair here
			AssertEquals ("AfterMonoKeyGeneration.KeySize", minKeySize, dsa.KeySize);
#if NET_2_0
			Assert ("PublicOnly", !dsa.PublicOnly);
#endif
		}
		// here Dispose is called (with true)
	}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:14,代码来源:DSACryptoServiceProviderTest.cs


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