public static void DoTest()
{
Console.WriteLine("使用 DSACryptoServiceProvider 类创建哈希值的数字签名,然后验证签名的例子!");
// 创建一个 DSA 算法的加密服务提供程序 (CSP) 实现的包装对象.
DSACryptoServiceProvider DSA = new DSACryptoServiceProvider();
// 需要被签名的数据.
byte[] HashValue = { 59, 4, 248, 102, 77, 97, 142, 201, 210, 12, 224, 93, 25, 41, 100, 197, 213, 134, 130, 135 };
Console.WriteLine("初始 Hash 数据.");
ByteArrayOutput.Print(HashValue);
// 签名处理.
byte[] SignedHashValue = DSASignHash(HashValue, DSA.ExportParameters(true), "SHA1");
Console.WriteLine("使用私钥签名的数据.");
ByteArrayOutput.Print(SignedHashValue);
// 验证签名.
if (DSAVerifyHash(HashValue, SignedHashValue, DSA.ExportParameters(false), "SHA1"))
{
Console.WriteLine("使用公钥验证 签名是有效的!");
}
else
{
Console.WriteLine("使用公钥验证 签名无效.");
}
}