证书
2015-10-04 11:52
337 查看
SelfCert: Create a Self-Signed Certificate Interactively (GUI) or Programmatically in .NET
By Keith SparkjoyWhile this isn’t new, I needed a new home for it since my old Pluralsight blog is gone now. Hopefully you’ll find it helpful!
It’s a bit of a pain to create self-signed certs using MAKECERT. So here’s a GUI-based tool that uses a combination of the .NET Framework and the CryptoAPI to create self-signed X.509 certificates. And it’s factored so that you can use the underlying library standalone – you can easily create certs programmatically now.
Here’s the GUI:
The GUI has some nifty features: you can create a PFX file directly, or you can save directly to a cert store of your choice. When you save to a cert store, an extra dialog pops up showing you where the private key file resides, so that you can adjust the ACL accordingly. I’ve got a “view private key” feature that launches explorer with the /select argument, taking you to the private key file so that you can set the ACL on it. Anyway, this extra dialog gives you some quick info you typically want, like the thumbprint. And there are buttons for browsing the cert store and viewing the certificate as well from here.
The GUI gens the RSA key pair on a background thread, so a) the app doesn’t lock up on you, and b) if you get tired of waiting for the key to gen, you can cancel easily enough
Here’s some code that does this programmatically by calling the Pluralsight.Crypto library that is underneath all of this. Those of you who are familiar with the CryptoAPI will recognize the key abstraction here, CryptContext.
static void GenSelfSignedCert() { using (CryptContext ctx = new CryptContext()) { ctx.Open(); X509Certificate2 cert = ctx.CreateSelfSignedCertificate( new SelfSignedCertProperties { IsPrivateKeyExportable = true, KeyBitLength = 4096, Name = new X500DistinguishedName("cn=localhost"), ValidFrom = DateTime.Today.AddDays(-1), ValidTo = DateTime.Today.AddYears(1), }); X509Certificate2UI.DisplayCertificate(cert); } }
Make sure you’ve got the Microsoft .NET Framework 3.5 installed. Self-Cert relies on it.
Download the project here, which includes binaries and sources. Feel free to use Pluralsight.Crypto in your own projects if you find it useful. Enjoy!
Ready to test your skills in .NET? See how they stack up with this assessment from Smarterer. Start this .NET test now
相关文章推荐
- andriod 实现新浪、QQ场地、朋友微信圈、微信朋友分享功能
- DirectX11 雾
- Hbase笔记二:简明系统架构
- 获取函数或程序相关的源码
- Matrix学习
- 经典算法题——第十三题 赫夫曼树
- MyEclipse 2014 破解图文详细教程
- Hbase笔记一:了解Hbase
- Java中有关Null的9件事
- 96. Unique Binary Search Trees (Tree; DFS)
- Asp.Net MVC 使用 DataAnnotations 进行模型验证
- 错误 10 非静态的字段、方法或属性“Test10.Program.a”要求对象引用
- HDU 1015 爆搜 /dfs+回溯
- 经典算法题——第十二题 线段树
- [WebView五学习]:调试Web Apps
- [leetcode 192] House Robber
- Eclipse插件本地扩展安装
- 结对编程项目(除附加题)开发过程
- spring-xmemcached 集成
- TCP协议发送SKB时ip_summed成员的设置 http://blog.csdn.net/justlinux2010/article/details/8508455