利用certmgr生成测试证书,利用C#检测证书是否存在

写成批处理

%~dp0makecert -sr localmachine -ss My -n CN=NCC -sky exchange -pe –r

C#检查证书是否存在

            X509Store store = new X509Store(StoreName.My, StoreLocation.LocalMachine);
            store.Open(OpenFlags.MaxAllowed);
            X509Certificate2Collection certs = store.Certificates.Find(X509FindType.FindBySubjectName, "NCC", false);

            if (certs.Count == 0 || certs[0].NotAfter < DateTime.Now)
            {
                Console.WriteLine("需要创建证书");
            }
posted @ 2011-05-12 19:14  chillwind  阅读(534)  评论(0)    收藏  举报