.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)博客
阅读(1813)
评论(3)
编辑
收藏
网摘
评论:
1278517
#1楼
2007-08-03 11:06 |
李海[未注册用户]
非常不错!加分100
回复
引用
#2楼
2008-05-15 18:51 |
QQ签名[未注册用户]
非常不错!
回复
引用
#3楼
2008-08-05 16:11 |
阿新
我用你的命名好像没有产生签名要的私钥
回复
引用
查看
刷新评论列表
刷新页面
返回页首
发表评论
昵称:
[登录]
[注册]
主页:
邮箱:
(仅博主可见)
验证码:
看不清,换一个
评论内容:
登录
注册
[使用Ctrl+Enter键快速提交评论]
0
729360
链接:
切换模板
导航:
网站首页
社区
新闻
博问
闪存
网摘
招聘
找找看
Google搜索
China-pub 计算机图书网上专卖店!6.5万品种 2-8折!
China-Pub 计算机绝版图书按需印刷服务
相关文章:
最新IT新闻:
Google Voice 上手
Google号召社区力量为互联网加速
Twitter无处不在 魔兽世界Twitter发送器插件发布
Firefox 3.5匆忙推出漏洞多 Mozilla本月将更新
预测:Twitter最可能收购的十家公司
相关链接:
<
2009年7月
>
日
一
二
三
四
五
六
28
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
与我联系
发短消息
搜索
常用链接
我的随笔
我的空间
我的短信
我的评论
更多链接
我的参与
我的新闻
最新评论
我的标签
留言簿
给我留言
查看留言
随笔档案
2007年5月 (1)
2007年4月 (3)
2007年2月 (2)
2007年1月 (1)
2006年12月 (3)
2006年11月 (6)
2006年10月 (4)
文章分类
代码细节
框架设计
最新评论
1. re: 对比 javascript url编码
标题中应该是encodeURI()方法.
--encode
2. re: 在C#中使用 makecert 创建自签名的证书
我用你的命名好像没有产生签名要的私钥
--阿新
3. re: 在C#中使用 makecert 创建自签名的证书
非常不错!
--QQ签名
4. re: 使用 DotnetOpenMail发送带附件的邮件
emailMessage.HeaderEncoding = DotNetOpenMail.Encoding.EncodingType.Base64; emailMessage.Head...
--冷火
5. re: 在C#中使用 makecert 创建自签名的证书
非常不错!加分100
--李海
阅读排行榜
1. 对比 javascript url编码(2386)
2. 在C#中使用 makecert 创建自签名的证书(1812)
3. 创建带签名的cab包的完整流程(792)
4. Google SiteMap的作用及协议格式详解[转摘] (516)
5. 使用 DotnetOpenMail发送带附件的邮件(449)
评论排行榜
1. 在C#中使用 makecert 创建自签名的证书(3)
2. 对比 javascript url编码(2)
3. 使用 DotnetOpenMail发送带附件的邮件(2)
4. 有关 java 与 C#细节不同(1)
5. UML视图使用(1)