.net中如何实现数字签名

fanz2000 2004-09-18 09:47:01
一个厂的经销商们要给这个厂传数字定单,如何知道此定单是哪个经销商传来的?那就是数字签名,至于有没被人改过和窃取过,以后再研究。谢谢。
...全文
655 13 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
quxilong1 2004-09-24
  • 打赏
  • 举报
回复
我觉得,要实现数字签名,首先要解决的问题是数字证书的读取,幸好,CAPICOM提供了很多接口,
有了它们,就可以编程实现,具体内容请看:msdn的安全内容里的CAPICOM。一定能成功。
khpcg 2004-09-18
  • 打赏
  • 举报
回复
每一个厂商有自己一个人得私人得钥匙,而你有相应配套得公钥
khpcg 2004-09-18
  • 打赏
  • 举报
回复
那个厂商用私人得钥匙加密摘要,你用相应得公钥解密,这是验证对方厂商得身份,同时对方不能抵赖他发过这个消息。而摘要是用哈稀算法计算文件出来得,你可以用同样得算法对文件进行计算,如果摘要一致,则表明没被修改,
ny_nicholas 2004-09-18
  • 打赏
  • 举报
回复
抵制日货
ny_nicholas 2004-09-18
  • 打赏
  • 举报
回复
up
test234 2004-09-18
  • 打赏
  • 举报
回复
up
athossmth 2004-09-18
  • 打赏
  • 举报
回复
ms-help://MS.VSCC/MS.MSDNVS/cptools/html/cpgrfstrongnameutilitysnexe.htm
51106354 2004-09-18
  • 打赏
  • 举报
回复
up
sjzwinfor 2004-09-18
  • 打赏
  • 举报
回复
http://www.ccw.com.cn/applic/prog/htm2003/20031219_091RQ.asp
happyjun2000 2004-09-18
  • 打赏
  • 举报
回复
// DSA 的数字签名
// RSA 类似,不过RSA比DSA慢得多,但比DSA安全。RSA可以选择关键字的大小,越大越安全
public static byte[] DsaCrypto_SignData ( string content , ref string dsaXmlString )
{
//先要将字符串转换为字节数组,这与编码有关。
// String content = "this is a test.";
byte[] bytes = Encoding.ASCII.GetBytes( content );
//选择签名方式,有RSA和DSA
DSACryptoServiceProvider dsac = new DSACryptoServiceProvider();
byte[] sign = dsac.SignData( bytes );
//当前 Dsa 对象的 xml 表示字符串 。
dsaXmlString = dsac.ToXmlString( false ) ;
//sign便是出来的签名结果。
return sign ;
}

// DSA 的数字签名认证
public static void DsaCrypto_VerifyData (string content , byte[] sign , string dsaXmlString )
{
byte[] bytes = Encoding.ASCII.GetBytes( content );
//下面是认证了
// DSACryptoServiceProvider dsac2 = new DSACryptoServiceProvider();
// dsac2.FromXmlString( dsac.ToXmlString( false ) );
// bool _verify = dsac2.VerifyData( bytes, sign );
DSACryptoServiceProvider dsac = new DSACryptoServiceProvider();
dsac.FromXmlString( dsaXmlString );
bool _verify = dsac.VerifyData( bytes, sign );
if ( _verify )
{
common.setMessage ( "通过" ) ;
}
else
{
common.setMessage ( "不能通过" ) ;
}
}
realljx 2004-09-18
  • 打赏
  • 举报
回复
好贴 收藏。。

勿忘国耻 抵制日货&up
sjzwinfor 2004-09-18
  • 打赏
  • 举报
回复
摘自msdn,详情请查阅

数字签名通常应用于表示较大数据的哈希值。下面的示例将数字签名应用于哈希值。首先,创建 RSACryptoServiceProvider 类的新实例以生成公钥/私钥对。接着,将 RSACryptoServiceProvider 传递给 RSAPKCS1SignatureFormatter 类的新实例。这就将该私钥传输给实际执行数字签名的 RSAPKCS1SignatureFormatter。在可以对哈希代码进行签名之前,必须指定要使用的哈希算法。本示例使用 SHA1 算法。最后,调用 RSAPKCS1SignatureFormatter.CreateSignature 方法以执行签名操作。
[Visual Basic]
Imports System
Imports System.Security.Cryptography

Module Module1
Sub Main()
'The hash value to sign.
Dim HashValue As Byte() = {59, 4, 248, 102, 77, 97, 142, 201, 210, 12, 224, 93, 25, 41, 100, 197, 213, 134, 130, 135}

'The value to hold the signed value.
Dim SignedHashValue() As Byte

'Generate a public/private key pair.
Dim RSA As New RSACryptoServiceProvider()

'Create an RSAPKCS1SignatureFormatter object and pass it
'the RSACryptoServiceProvider to transfer the private key.
Dim RSAFormatter As New RSAPKCS1SignatureFormatter(RSA)

'Set the hash algorithm to SHA1.
RSAFormatter.SetHashAlgorithm("SHA1")

'Create a signature for HashValue and assign it to
'SignedHashValue.
SignedHashValue = RSAFormatter.CreateSignature(HashValue)
End Sub
End Module

using System;
using System.Security.Cryptography;
[C#]
class Class1
{
static void Main()
{
//The hash value to sign.
byte[] HashValue = {59,4,248,102,77,97,142,201,210,12,224,93,25,41,100,197,213,134,130,135};

//The value to hold the signed value.
byte[] SignedHashValue;

//Generate a public/private key pair.
RSACryptoServiceProvider RSA = new RSACryptoServiceProvider();

//Create an RSAPKCS1SignatureFormatter object and pass it the
//RSACryptoServiceProvider to transfer the private key.
RSAPKCS1SignatureFormatter RSAFormatter = new RSAPKCS1SignatureFormatter(RSA);

//Set the hash algorithm to SHA1.
RSAFormatter.SetHashAlgorithm("SHA1");

//Create a signature for HashValue and assign it to
//SignedHashValue.
SignedHashValue = RSAFormatter.CreateSignature(HashValue);
}
}
tendotnet 2004-09-18
  • 打赏
  • 举报
回复
也想了解,帮顶!!

111,096

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧