title: Certenroll on Azure - Generating self signed certificates
body: <p>I have built a creation self-signing certificates using <strong>Certenroll</strong> (<strong>CERTENROLLLib</strong>). All works locally but as soon as I <strong>deploy</strong> it to <strong>Azure</strong> I get either:</p>
  
  <blockquote>
    <p>Server API error: Message:
    CertEnroll::CX509Enrollment::_CreateRequest: Access is denied.
    0x80070005 (WIN32: 5 ERROR_ACCESS_DENIED), StackTrace:    at
    CERTENROLLLib.IX509Enrollment2.CreateRequest(EncodingType Encoding)<br>
    at
    Foo.Api.Core.Providers.CertificateProvider.GenerateBase64EncodedPfx(String
    subjectName, Int32 certificateValidityInYears, String password)    at
    Foo.Api.Core.Services.CertificateService.d__4.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---    at
    System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
    task)    at
    System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
    task)    at
    Foo.ServerApi.Services.DocumentSigningService.d__7.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---    at
    System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
    task)    at
    System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
    task)    at
    Foo.ServerApi.Services.DocumentSigningService.d__5.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---    at
    System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
    task)    at
    System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
    task)    at
    System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)<br>
    at
    Foo.ServerApi.Controllers.DocumentController.&lt;>c__DisplayClass10_1.&lt;b__5>d.MoveNext()</p>
  </blockquote>
  
  <p>if using: </p>
  
  <pre><code>var cert = new CX509CertificateRequestCertificate();
              cert.InitializeFromPrivateKey(X509CertificateEnrollmentContext.ContextMachine, privateKey, "");
  </code></pre>
  
  <p>or</p>
  
  <blockquote>
    <p>Server API error: Message:
    CertEnroll::CX509CertificateRequestCertificate::InitializeFromPrivateKey:
    The parameter is incorrect. 0x80070057 (WIN32: 87
    ERROR_INVALID_PARAMETER), StackTrace:    at
    CERTENROLLLib.IX509CertificateRequestCertificate2.InitializeFromPrivateKey(X509CertificateEnrollmentContext
    Context, IX509PrivateKey pPrivateKey, String strTemplateName)    at
    Foo.Api.Core.Providers.CertificateProvider.GenerateBase64EncodedPfx(String
    subjectName, Int32 certificateValidityInYears, String password)    at
    Foo.Api.Core.Services.CertificateService.d__4.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---    at
    System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
    task)    at
    System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
    task)    at
    Foo.ServerApi.Services.DocumentSigningService.d__7.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---    at
    System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
    task)    at
    System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
    task)    at
    Foo.ServerApi.Services.DocumentSigningService.d__5.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---    at
    System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
    task)    at
    System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
    task)    at
    System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)<br>
    at
    Foo.ServerApi.Controllers.DocumentController.&lt;>c__DisplayClass10_1.&lt;b__5>d.MoveNext()</p>
  </blockquote>
  
  <p>if using: </p>
  
  <pre><code>var cert = new CX509CertificateRequestCertificate();
              cert.InitializeFromPrivateKey(X509CertificateEnrollmentContext.ContextUser, privateKey, "");
  </code></pre>
  
  <p>Is there any way how to overcome this issue with Certenroll on Azure?</p>
  
  <p><strong>Edit</strong>: final error that lead me to the correct path.</p>
  
  <blockquote>
    <p>Server API error: Message: CertEnroll::CX509PrivateKey::Create: The
    system cannot find the file specified. 0x80070002 (WIN32: 2
    ERROR_FILE_NOT_FOUND), StackTrace:    at
    CERTENROLLLib.IX509PrivateKey2.Create()    at
    Foo.Api.Core.Providers.CertificateProvider.GenerateBase64EncodedPfx(String
    subjectName, Int32 certificateValidityInYears, String password)    at
    Foo.Api.Core.Services.CertificateService.d__4.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---    at
    System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
    task)    at
    System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
    task)    at
    Foo.ServerApi.Services.DocumentSigningService.d__7.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---    at
    System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
    task)    at
    System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
    task)    at
    Foo.ServerApi.Services.DocumentSigningService.d__5.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---    at
    System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
    task)    at
    System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
    task)    at
    System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)<br>
    at
    Foo.ServerApi.Controllers.DocumentController.&lt;>c__DisplayClass10_1.&lt;b__5>d.MoveNext()</p>
  </blockquote>