Cannot find the specified object using X509Certificate2

I am trying to upload a file containing a private key to access Google Calendar API. Following this guide. For this, I created this code:

var certificate = new X509Certificate2("client_secret.json", "notasecret", X509KeyStorageFlags.Exportable);

I uploaded the file client_secret.jsoninside my solution, this is the file path:"...\Visual Studio 2015\Projects\Calendar\Calendar\bin\Debug\client_secret.json"

but it seems that the code cannot find the file and return this error:

Cannot find the specified object using X509Certificate2

I also set the property Always copyto Copy in the output directoryin the file to read.

+4
source share
2 answers

After a few headaches, I was able to figure out where it is wrong, as I said in the comments, I am creating a certificate:

, , - API Google, " " " ", API, , json.

X509Certificate2, :

1. " " , , " ".

2. , , . ( ).

3. , Create Key.

4. P12 "".

5. , , , :

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

, key.p12 - , notasecret - , 4, - , .

, , , - .

, MegaTron, , - .

+6

MachineKeySet. , :

var certificate = new X509Certificate2("client_secret.json", "notasecret", X509KeyStorageFlags.Exportable | X509KeyStorageFlags.MachineKeySet);
+1

All Articles