I\'m unit testing a .NET application; some of the unit tests involve programmatically generating X509Certificate2 objects.
I don\'t care about actual signing/private
I would suggest the following:
Code:
byte[] embeddedCert;
Assembly thisAssembly = Assembly.GetAssembly(typeof(MyType));
using (Stream certStream = thisAssembly.GetManifestResourceStream("YourProjectName.localhost.pfx"))
{
embeddedCert = new byte[certStream.Length];
certStream.Read(embeddedCert, 0, (int)certStream.Length);
}
_signingCert = new X509Certificate2(embeddedCert, "password");
At this point you should be good to go as far as interacting with the certificate. You can create different variants if your unit tests have different needs.