Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can you get a certificate in code on Windows Azure

I'm trying to create our own WIF Identity Provider and run it on Azure but I'm struggling when trying to automatically generate the Federation Metadata.

This line does not appear to work on Azure:

CertificateUtil.GetCertificate(StoreName.My, StoreLocation.LocalMachine, signingCertificateName);

The certificate is uploaded to Azure, how can I get hold of it?

Thanks

like image 479
Max Avatar asked Apr 14 '11 10:04

Max


1 Answers

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)

like image 155
knightpfhor Avatar answered Sep 23 '22 21:09

knightpfhor