CreateSignature() public method

Creates the DSA signature for the specified data.
public CreateSignature ( byte rgbHash ) : byte[]
rgbHash byte The data to be signed.
return byte[]
Ejemplo n.º 1
0
	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)
	}
Ejemplo n.º 2
0
	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");
	}
	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)
	}