.net 随笔
记录你的轨迹
博客园
首页
新随笔
联系
订阅
管理
随笔-20 评论-8 文章-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)博客
阅读(616)
评论(2)
编辑
收藏
评论:
#1楼
2007-08-03 11:06 |
李海 [未注册用户]
非常不错!加分100
回复
引用
查看
#2楼
2008-05-15 18:51 |
QQ签名 [未注册用户]
非常不错!
回复
引用
查看
社区
新闻
新用户注册
刷新评论列表
标题
姓名
主页
Email
(只有博主才能看到)
验证码
*
看不清,换一张
内容(请不要发表任何与政治相关的内容)
Remember Me?
登录
使用高级评论
新用户注册
返回页首
恢复上次提交
[使用Ctrl+Enter键可以直接提交]
另存
打印
最新IT新闻:
博客园新闻频道
博客园首页
社区
<
2008年7月
>
日
一
二
三
四
五
六
29
30
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
31
1
2
3
4
5
6
7
8
9
与我联系
发短消息
常用链接
我的随笔
我的空间
我的短信
我的评论
更多链接
我的参与
我的新闻
最新评论
我的标签
留言簿
(1)
给我留言
查看留言
随笔档案
2007年5月 (1)
2007年4月 (3)
2007年2月 (2)
2007年1月 (1)
2006年12月 (3)
2006年11月 (6)
2006年10月 (4)
文章分类
代码细节
框架设计
搜索
最新评论
1. re: 在C#中使用 makecert 创建自签名的证书
非常不错!
--QQ签名
阅读排行榜
1. 对比 javascript url编码(930)
2. 在C#中使用 makecert 创建自签名的证书(616)
3. 使用 DotnetOpenMail发送带附件的邮件(302)
4. Google SiteMap的作用及协议格式详解[转摘] (301)
5. 创建带签名的cab包的完整流程(246)
评论排行榜
1. 使用 DotnetOpenMail发送带附件的邮件(2)
2. 在C#中使用 makecert 创建自签名的证书(2)
3. 创建带签名的cab包的完整流程(1)
4. 有关 java 与 C#细节不同(1)
5. 对比 javascript url编码(1)