c# - Azure Web Application new X509Certificate2() causing System.Security.Cryptography.CryptographicException: Access denied -


right uploading .pfx file, taking in password , calling

var cert = new x509certificate2(filedata, password); 

and storing things thumbprint, etc. not need store on server, validate valid cert , store information. on local works (obviously have better access key store) when put in azure error:

system.security.cryptography.cryptographicexception: access denied.

is there way information sidestepping or use method without getting access denied? not certs, let me know if need more information. thank you.

when opening pfx on windows private keys written disk. deleted later (unless specify persistkeyset), still have written (ish).

where written?

  • if specify x509keystorageflags.machinekeyset: in machine keystore, need administrator.
  • if specify x509keystorageflags.userkeyset: in user keystore, user profile needs exist/load.
  • if don't specify either:
    • if pfx itself has encoded key belongs in machine key set, machine keystore (admin required).
    • otherwise user keystore (profile required).

given "access denied" i'd guess hit case pfx specified machine keystore, resolve you'd change call to

new x509certificate2(filedata, password, x509keystorageflags.userkeyset)

and should work. if specify userkeyset , still error, might profile-loading problem.

there is option load pfx without writing private keys disk, it's not available in .net framework (though added .net core). if need p/invoking pfximportcertstore pkcs12_no_persist_key flag, pass resultant hcertstore value x509store.ctor(intptr) , read certificate(s) via x509store.certificates property. note, though, of .net framework won't understand these cert objects have associated private keys, they'll behave public-only certificate objects.


Comments

Popular posts from this blog

sql server - Cannot query correctly (MSSQL - PHP - JSON) -

php - trouble displaying mysqli database results in correct order -

C++ Linked List -