社区
C#
帖子详情
用C#去做数字签名
loveyouchina
2007-08-08 03:46:00
用C#语言怎么从本机去查到指定容器名的证书,并且去做签名,或者去进行签名的验证.我用CertOpenStore()和函数CertFindCertificateInStore去读证书的信息的时候CertFindCertificateInStore总读不出来信息,有那为朋友作过,介绍一下函数的声明,结构体的声明,谢谢
...全文
964
5
打赏
收藏
用C#去做数字签名
用C#语言怎么从本机去查到指定容器名的证书,并且去做签名,或者去进行签名的验证.我用CertOpenStore()和函数CertFindCertificateInStore去读证书的信息的时候CertFindCertificateInStore总读不出来信息,有那为朋友作过,介绍一下函数的声明,结构体的声明,谢谢
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
5 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
loveyouchina
2007-08-15
打赏
举报
回复
不好意思,这几天密码上不来了,现在我调试程序的时候报Attemp to read or write protected
Memory,这种错误一般怎么解决,谢谢.应该给大家结帖子了
loveyouchina
2007-08-09
打赏
举报
回复
谢谢,你的回复.
我这里主要是想知道怎么用pki的函数,怎么去查找已有的证书,并且从证书里获得相关的信息,来进行一些验证
wuhuiITren
2007-08-08
打赏
举报
回复
mark
紫气东来_999
2007-08-08
打赏
举报
回复
using System;
using System.Security.Cryptography;
using System.IO;
using System.Text;
using System.Web.Security;
namespace Paladin.Common
{
/// <summary>
/// Security 的摘要说明。
/// 对称加密算法 : DES / TripleDES / RC2 / Rijndael
/// 非对称加密算法 : DSA / RSA
/// </summary>
public class Cryptography
{
public Cryptography()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
// DES 的加密方法 。
// 私钥加密 / 对称算法 。
public static string Encrypt_Des( string cleanString )
{
//.NET 框架提供的对称加密类需要一个密钥和一个新的 IV 来加密和解密数据。
//每当使用默认的构造函数创建其中一个托管对称加密类的新实例时,就会自动创建新的密钥和 IV
//DES 使用 64 位密钥、64 位块来加密和解密数据。每个数据块迭代 16 次以生成加密文本。
//初始化向量(IV) 用来第一次对数据块进行加密 。
byte[] KEY_64 = {42, 16, 93, 156, 78, 4, 218, 32}; // 指定的 Key
byte[] IV_64 = {55, 103, 246, 79, 36, 99, 167, 3}; // 初始化向量(IV)
DESCryptoServiceProvider provider = new DESCryptoServiceProvider ( ) ;
MemoryStream ms = new MemoryStream();
CryptoStream cs = new CryptoStream( ms , provider.CreateEncryptor( KEY_64,IV_64 ) , CryptoStreamMode.Write ) ;
StreamWriter sw = new StreamWriter( cs ) ;
sw.Write( cleanString ) ;
sw.Flush( ) ;
cs.FlushFinalBlock( ) ;
ms.Flush( ) ;
return Convert.ToBase64String( ms.GetBuffer( ) , 0 , int.Parse( ( ms.Length.ToString ( ) ) ) ) ;
}
// DES 的解密方法 。
// 私钥加密 / 对称算法 。
public static string Decrypt_Des( string encryptedString )
{
byte[] KEY_64 = {42, 16, 93, 156, 78, 4, 218, 32};
byte[] IV_64 = {55, 103, 246, 79, 36, 99, 167, 3};
DESCryptoServiceProvider provider = new DESCryptoServiceProvider ( ) ;
byte[] buffer = Convert.FromBase64String( encryptedString ) ;
MemoryStream ms = new MemoryStream ( buffer ) ;
CryptoStream cs = new CryptoStream( ms,provider.CreateDecryptor( KEY_64,IV_64 ) , CryptoStreamMode.Read ) ;
StreamReader sr = new StreamReader( cs ) ;
return sr.ReadToEnd ( ) ;
}
// hash 加密
public static string Encrypt_Hash(string cleanString)
{
Byte[] clearBytes = new UnicodeEncoding().GetBytes(cleanString);
Byte[] hashedBytes = ((HashAlgorithm) CryptoConfig.CreateFromName("MD5")).ComputeHash(clearBytes);
return BitConverter.ToString(hashedBytes);
}
// sha1 的方式加密密码
public static String Encrypt_Sha1( String oriPassWrd )
{
String returnstr="";
returnstr = FormsAuthentication.HashPasswordForStoringInConfigFile( oriPassWrd , "sha1" );
return returnstr;
}
// 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 ( "不能通过" ) ;
}
}
}//class
}
紫气东来_999
2007-08-08
打赏
举报
回复
//给指定文件生成一个数字签名文件
private void GenerateADigitalSignatureFile(string fName, string fDigName)
{
DSACryptoServiceProvider dsa = new DSACryptoServiceProvider();
FileStream fs = new FileStream(fName,FileMode.Open,FileAccess.Read);
byte[] bt = new byte[fs.Length];
textBox7.Text = dsa.ToXmlString(false); //生成的公匙
bt = dsa.SignData(fs);
//string str = BitConverter.ToString(bt);
FileStream fw = new FileStream(fDigName,FileMode.OpenOrCreate,FileAccess.Write);
fw.Write(bt,0,bt.Length);
fs.Close();
fw.Close();
}
//验证文件的数字签名
private bool VerifyFileDig(string fName, string fDigName, string key)
{
DSACryptoServiceProvider dsa = new DSACryptoServiceProvider();
FileStream f = new FileStream(fName,FileMode.Open,FileAccess.Read);
byte[] bfile = new byte[f.Length];
f.Read(bfile,0,bfile.Length);
f.Close();
FileStream fd = new FileStream(fDigName,FileMode.Open,FileAccess.Read);
byte[] bd = new byte[fd.Length];
fd.Read(bd,0,bd.Length);
fd.Close();
dsa.FromXmlString(key);
return dsa.VerifyData(bfile,bd);
}
c#
数字签名
模拟系统
数字签名
c#
数字签名
c#
数字签名
c#
数字签名
c#
数字签名
c#
数字签名
c#
数字签名
c#
数字签名
c#
数字签名
c#
数字签名
c#
数字签名
c#
数字签名
c#
数字签名
c#
数字签名
c#
数字签名
c#
数字签名
c#
数字签名
c#
数字签名
c#
...
C#
模拟
数字签名
过程
(1) 发方A用自己的私钥PVA,采用非对称RSA算法,将原文信息进行哈希(hash)运算,并对hash值进行加密,即得
数字签名
DS;(RSACryptoServiceProvider.SignData()) (3) 发方A用对称算法AES的对称密钥SK对原文...
winform实现
数字签名
实例
C#
实现的
数字签名
实例,非常好的一个例子 winform实现
数字签名
实例开发环境:VS2008 |
C#
实现
数字签名
算法
C#
实现的
数字签名
算法源代码
C#
实现的
数字签名
算法源代码
基于RSA算法的
数字签名
系统
C#
实现
基于RSA算法的
数字签名
系统,
C#
实现。毕设的题目,上传给大家分享。
C#
110,538
社区成员
642,577
社区内容
发帖
与我相关
我的任务
C#
.NET技术 C#
复制链接
扫一扫
分享
社区描述
.NET技术 C#
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
让您成为最强悍的C#开发者
试试用AI创作助手写篇文章吧
+ 用AI写文章