title: Azure - X509Certificate2 constructor error (.Net Core): The network password is not correct
body: <p>I am loading a .pfx cert from embedded resource file in my project.  The embedded resource file is loaded properly and I'm getting the raw data correctly - code:</p>
  
  <pre><code> using (Stream stream = assembly.GetManifestResourceStream(resourceName))
   {
         try
         {
                  Byte[] raw = new Byte[stream.Length];
  
                  for (Int32 i = 0; i &lt; stream.Length; i++)
                  {
                      raw[i] = (Byte)stream.ReadByte();
                  }
                  //X509Certificate2 cert = new X509Certificate2(raw, password);
                  X509Certificate2 cert = new X509Certificate2(raw, password, X509KeyStorageFlags.MachineKeySet);
                  //Both of the above attempts give me invalid network password
                  //errors on Azure.
                  builder.AddSigningCredential(cert);
                  builder.AddValidationKey(cert);
         }
         catch (Exception e)
         {
              //Notify me of exception
         }
  } //end using
  </code></pre>
  
  <p>However, when attempting to initialize a new X509Certificate2 object, I think it's attempting to access more certificates in the store which don't exist or something </p>
  
  <p>(according to this question:</p>
  
  <p><a href="https://stackoverflow.com/questions/8286110/asp-net-the-specified-network-password-is-not-correct">ASP.NET - The specified network password is not correct</a></p>
  
  <p>)</p>
  
  <p>Full error:
  Internal.Cryptography.CryptoThrowHelper+WindowsCryptographicException: The specified network password is not correct
     at Internal.Cryptography.Pal.CertificatePal.FilterPFXStore(Byte[] rawData, SafePasswordHandle password, PfxCertStoreFlags pfxCertStoreFlags)
     at Internal.Cryptography.Pal.CertificatePal.FromBlobOrFile(Byte[] rawData, String fileName, SafePasswordHandle password, X509KeyStorageFlags keyStorageFlags)
     at System.Security.Cryptography.X509Certificates.X509Certificate..ctor(Byte[] rawData, String password, X509KeyStorageFlags keyStorageFlags)</p>