Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Importing a P12/PFX key location relative to solution folder

I've recently tried to jump into the wonderful world of the Google Analytics API and, for the life of me, can't get the P12 key path to be picked up in a location relative to my solution file, so (this is what I have so far):

var certificate = new X509Certificate2("C:\\mykey.p12", "notasecret", X509KeyStorageFlags.MachineKeySet | X509KeyStorageFlags.Exportable);

This works fine, no problem! But, I'll be pushing this to Azure, so C:\ simply won't work.

I've tried:

var certificate = new X509Certificate2("mykey.p12", "notasecret", X509KeyStorageFlags.MachineKeySet | X509KeyStorageFlags.Exportable);

with the key in the root path of my solution, nada, this simply won't work. I've been scouring tutorials out there with people saying it's possible, but not providing anything about how the key was referenced locally to the solution so it'll work on Azure (with MachineKeySet).

Thanks in advance.

like image 205
Chris Dixon Avatar asked Aug 06 '14 08:08

Chris Dixon


1 Answers

var certificate = new X509Certificate2("mykey.p12", "notasecret", X509KeyStorageFlags.MachineKeySet | X509KeyStorageFlags.Exportable);

would work if your certificate was loaded into your bin folder. So set the certificates build action to 'Content' and its Copy to Output Directory to 'Copy if newer'

like image 61
Greg Randall Avatar answered Oct 29 '22 06:10

Greg Randall