随笔-20  评论-9  文章-0  trackbacks-0
 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 (博主才能看到) 
验证码 *  看不清,换一张 [登录][注册]
内容(请不要发表任何与政治相关的内容)  
  登录  使用高级评论  新用户注册  返回页首  恢复上次提交      
"五向定位"职业成长路线公开课(上海、南京、大连)
Google站内搜索


相关链接: