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:
using (Stream stream = assembly.GetManifestResourceStream(resourceName))
{
try
{
Byte[] raw = new Byte[stream.Length];
for (Int32 i = 0; i < 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
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
(according to this question:
ASP.NET - The specified network password is not correct
)
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)