一个厂的经销商们要给这个厂传数字定单,如何知道此定单是哪个经销商传来的?那就是数字签名,至于有没被人改过和窃取过,以后再研究。谢谢。
也想了解,帮顶!!
摘自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);
}
}
好贴 收藏。。
勿忘国耻 抵制日货&up
// 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 ( "不能通过" ) ;
}
}
http://www.ccw.com.cn/applic/prog/htm2003/20031219_091RQ.asp
up
ms-help://MS.VSCC/MS.MSDNVS/cptools/html/cpgrfstrongnameutilitysnexe.htm
up
up
抵制日货
那个厂商用私人得钥匙加密摘要,你用相应得公钥解密,这是验证对方厂商得身份,同时对方不能抵赖他发过这个消息。而摘要是用哈稀算法计算文件出来得,你可以用同样得算法对文件进行计算,如果摘要一致,则表明没被修改,
每一个厂商有自己一个人得私人得钥匙,而你有相应配套得公钥
我觉得,要实现数字签名,首先要解决的问题是数字证书的读取,幸好,CAPICOM提供了很多接口,
有了它们,就可以编程实现,具体内容请看:msdn的安全内容里的CAPICOM。一定能成功。
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。一定能成功。