.net 随笔
记录你的轨迹
博客园
首页
社区
新随笔
联系
订阅
管理
随笔-20 评论-10 文章-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)博客
阅读(3985)
评论(3)
编辑
收藏
评论:
1278517
#1楼
2007-08-03 11:06
|
李海[未注册用户]
非常不错!加分100
回复
引用
#2楼
2008-05-15 18:51
|
QQ签名[未注册用户]
非常不错!
回复
引用
#3楼
2008-08-05 16:11
|
阿新
我用你的命名好像没有产生签名要的私钥
回复
引用
查看
注册用户登录后才能发表评论,请
登录
或
注册
,
返回博客园首页
。
首页
博问
闪存
新闻
园子
招聘
知识库
最新IT新闻
:
·
动视暴雪确认今年第二季度推出《暗黑破坏神3》
·
官方承认 Google Bar 逆行倒施
·
创意融资平台Kickstarter迎来重大突破,两个项目各获融资超过100万美元
·
商务社交网站LinkedIn发布2011第四季度财报,收入1.67亿美元,同比增长105%
·
PaperKarma:“拍”走垃圾邮件
»
更多新闻...
最新知识库文章
:
·
如何学习一门新的编程语言?
·
学习不同编程语言的重要性
·
为什么我喜欢富于表达性的编程语言
·
计算机专业的女生为什么要学编程
·
前端必读:浏览器内部工作原理
»
更多知识库文章...
China-pub 2011秋季教材巡展
China-Pub 计算机绝版图书按需印刷服务
昵称:
冰封王座(.net)博客
园龄:
5年8个月
粉丝:
0
关注:
0
<
2012年2月
>
日
一
二
三
四
五
六
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
1
2
3
4
5
6
7
8
9
10
搜索
常用链接
我的随笔
我的评论
我的参与
最新评论
我的标签
随笔档案
2007年5月 (1)
2007年4月 (3)
2007年2月 (2)
2007年1月 (1)
2006年12月 (3)
2006年11月 (6)
2006年10月 (4)
文章分类
代码细节
框架设计
最新评论
阅读排行榜
评论排行榜
推荐排行榜