How can you get a certificate in code on Windows Azure

家住魔仙堡 提交于 2019-11-30 07:28:05

Try this blog post: http://blogs.msdn.com/b/jnak/archive/2010/01/29/installing-certificates-in-windows-azure-vms.aspx

It suggests code like:

X509Certificate2Collection selectedCerts = new X509Certificate2Collection();

X509Store store = new X509Store(StoreName.My, StoreLocation.CurrentUser);
store.Open(OpenFlags.OpenExistingOnly | OpenFlags.ReadOnly);
foreach (X509Certificate2 cert in store.Certificates)
{
    // do stuff with cert
}

As a slight variation on other answers, if you just want to get one certificate rather than iterate through all of them you could do something like this:

var store = new X509Store(StoreName.My, StoreLocation.LocalMachine);

store.Open(OpenFlags.ReadOnly | OpenFlags.OpenExistingOnly);

X509Certificate2Collection matchedCertificates =
     store.Certificates.Find(X509FindType.FindBySubjectName, signingCertificateName, true);

if (matchedCertificates.Count > 0)
{
    myCertificate = matchedCertificates[0]; 
}

(which also is not Azure specific)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!