本文整理汇总了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)
}
示例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");
}
示例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)
}