.net 随笔
记录你的轨迹
博客园
首页
社区
新随笔
联系
订阅
管理
随笔-20 评论-9 文章-0 trackbacks-0
在C#中使用 makecert 创建自签名的证书
class
Program
{
static
void
Main(
string
[] args)
{
X509Certificate2 cert
=
CreateCertificate();
//
cert.ToString();
Console.Write(cert.ToString());
Console.Read();
}
public
static
X509Certificate2 CreateCertificate()
{
//
makecert -r -pe -n "CN=TestUser" -ss my -sr currentuser
//
-sky exchange .\TestUser.cer
//
const string MakeCert = "C:\\Program Files\\Microsoft Visual Studio 8\\Common7\\Tools\\Bin\\makecert.exe";
const
string
MakeCert
=
"
C:\\Program Files\\Microsoft Visual Studio 8\\SDK\\v2.0\\Bin\\makecert.exe
"
;
//
string fileName = Path.ChangeExtension(Path.GetTempFileName(), "cer");
string
fileName
=
Path.ChangeExtension(
"
d:\\
"
,
"
cer
"
);
string
userName
=
Guid.NewGuid().ToString();
string
arguments
=
string
.Format(
"
-r -pe -n \
"
CN
=
{
0
}
\
"
-ss my -sr currentuser -sky exchange \
"
{
1
}
\
""
,
userName, fileName);
Process p
=
Process.Start(MakeCert, arguments);
p.WaitForExit();
byte
[] certBytes
=
ReadFile(fileName);
X509Certificate2 cert
=
new
X509Certificate2(certBytes);
return
cert;
}
internal
static
byte
[] ReadFile(
string
fileName)
{
using
(FileStream f
=
new
FileStream(fileName, FileMode.Open, FileAccess.Read))
{
int
size
=
(
int
)f.Length;
byte
[] data
=
new
byte
[size];
size
=
f.Read(data,
0
, size);
return
data;
}
}
}
posted on 2007-04-27 10:39
冰封王座(.net)博客
阅读(836)
评论(3)
编辑
收藏
评论:
#1楼
2007-08-03 11:06 |
李海 [未注册用户]
非常不错!加分100
回复
引用
#2楼
2008-05-15 18:51 |
QQ签名 [未注册用户]
非常不错!
回复
引用
#3楼
2008-08-05 16:11 |
阿新
我用你的命名好像没有产生签名要的私钥
回复
引用
查看
新用户注册
刷新评论列表
标题
姓名
主页
Email
(博主才能看到)
验证码
*
看不清,换一张
[
登录
][
注册
]
内容(请不要发表任何与政治相关的内容)
网站首页
新闻频道
社区
小组
博问
网摘
闪存
找找看
Remember Me?
登录
使用高级评论
新用户注册
返回页首
恢复上次提交
[使用Ctrl+Enter键可以直接提交]
"五向定位"职业成长路线公开课(上海、南京、大连)
Google站内搜索
相关文章:
使用Visual Studio2005入门.Net2.0系列视频教程
automation服务器不能创建对象
相关链接:
最新IT新闻:
MySpace推自助广告平台MyAds
Facebook创始人:信息共享或存摩尔定律
微软承认Vista用户账户控制功能有问题
资本寒冬侵袭中国视频网站 营销春天或不远
金融风暴波及全球创业板 中国概念股难独善其身
<
2007年4月
>
日
一
二
三
四
五
六
25
26
27
28
29
30
31
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
1
2
3
4
5
与我联系
发短消息
搜索
常用链接
我的随笔
我的空间
我的短信
我的评论
更多链接
我的参与
我的新闻
最新评论
我的标签
留言簿
(1)
给我留言
查看留言
随笔档案
2007年5月 (1)
2007年4月 (3)
2007年2月 (2)
2007年1月 (1)
2006年12月 (3)
2006年11月 (6)
2006年10月 (4)
文章分类
代码细节
框架设计
最新评论
阅读排行榜
1. 对比 javascript url编码(1131)
2. 在C#中使用 makecert 创建自签名的证书(836)
3. 创建带签名的cab包的完整流程(381)
4. Google SiteMap的作用及协议格式详解[转摘] (377)
5. 使用 DotnetOpenMail发送带附件的邮件(363)
评论排行榜
1. 在C#中使用 makecert 创建自签名的证书(3)
2. 使用 DotnetOpenMail发送带附件的邮件(2)
3. 有关 java 与 C#细节不同(1)
4. 对比 javascript url编码(1)
5. UML视图使用(1)