.net中如何实现数字签名

一个厂的经销商们要给这个厂传数字定单,如何知道此定单是哪个经销商传来的?那就是数字签名,至于有没被人改过和窃取过,以后再研究。谢谢。
1楼 

也想了解,帮顶!!
2楼 

摘自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);  
        }  
  }  
 
3楼 

好贴   收藏。。  
   
  勿忘国耻   抵制日货&up  
 
4楼 

//   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   (   "不能通过"   )   ;  
  }  
  }
5楼 

http://www.ccw.com.cn/applic/prog/htm2003/20031219_091RQ.asp
6楼 

up
7楼 

ms-help://MS.VSCC/MS.MSDNVS/cptools/html/cpgrfstrongnameutilitysnexe.htm
8楼 

up
9楼 

up
10楼 

抵制日货
11楼 

那个厂商用私人得钥匙加密摘要,你用相应得公钥解密,这是验证对方厂商得身份,同时对方不能抵赖他发过这个消息。而摘要是用哈稀算法计算文件出来得,你可以用同样得算法对文件进行计算,如果摘要一致,则表明没被修改,
12楼 

每一个厂商有自己一个人得私人得钥匙,而你有相应配套得公钥
13楼 

我觉得,要实现数字签名,首先要解决的问题是数字证书的读取,幸好,CAPICOM提供了很多接口,  
  有了它们,就可以编程实现,具体内容请看:msdn的安全内容里的CAPICOM。一定能成功。   
 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值