Search code examples
c#azurecertificatex509certificate2azure-management-api

How I can get an azure management certificate?


I have a console application running on an Azure cloud service VM that need getting a management certificate.

My certificate is loaded on SETTINGS/CERTIFICATE but what should I do next?

I tried something like this:

 X509Store certStore = new X509Store(StoreName.My, StoreLocation.LocalMachine);
 certStore.Open(OpenFlags.OpenExistingOnly | OpenFlags.ReadOnly);
 X509Certificate2Collection certCollection = certStore.Certificates
      .Find(X509FindType.FindByThumbprint, certificateThumb, false);
 X509Certificate2 certificate = certCollection[0];

Maybe I don't understand how works SETTINGS/CERTIFICATE but I only get an error message saying there are no certificate having this thumbprint.

EDIT: I complete my question. Is this enough to make a declaration in SETTINGS/CERTIFICATE?


Solution

  • I answer my question.

    In fact we have 2 way to use management certificate.

    1. create a publishsetting file with the powershell command get-AzurePublishsettingsFile. The command adds a .cer certificate in management store as well. We just have to deserialize the base 64 certificate found into the file and add it in the credentials
    2. create a certificate with makecert. Load the .cer in the azure management store and the .pfx in the local store from where the client application is installed

    some links:

    http://www.wadewegner.com/2011/11/programmatically-installing-and-using-your-management-certificate-with-the-new-publishsettings-file/