Search code examples
.netazurecertificatex509certificatewif

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


Solution

  • 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
    }