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
There is one more simple way of doing it.
Code:
string certificate = "cert.pfx";
string certPath = string.Format("{0}/App_Data/{1}", HttpRuntime.AppDomainAppPath, certificate);
byte[] bytes = Util.FileToArray(certPath);
X509Certificate2 publicKey = new X509Certificate2(bytes, "somepassoword");