c# - “System.Security.Cryptography.CryptographicException: Keyset does not exist” when reading private key from remote machine -


i trying decrypt data using certificate private key. works fine when certificate installed on local machine (i using self signed certificate testing , have private key certificate) when try access private key remote machine using same code, "keyset not exist" exception.

i using console application testing, , have made sure id have read permissions on private key on remote server. here sample code using:

var store = new x509store(@"\\server1\my", storelocation.localmachine); store.open(openflags.readonly); var result = store.certificates.find(x509findtype.findbysubjectname, "server1.test.com", false); var certificate = result[0]; store.close();  //this succeeds both local , remote server var rsapublic = (rsacryptoserviceprovider)certificate.publickey.key;  //this succeeds local, fails remote server var rsaprivate = (rsacryptoserviceprovider)certificate.privatekey; 

here exception call stack

unhandled exception: system.security.cryptography.cryptographicexception: keyset not exist     @ system.security.cryptography.utils.createprovhandle(cspparameters parameters, boolean randomkeycontainer)    @ system.security.cryptography.utils.getkeypairhelper(cspalgorithmtype keytype, cspparameters parameters, boolean randomkeycontainer, int32 dwkeysize, safeprovhandle& safeprovhandle, safekeyhandle& safekeyhandle)    @ system.security.cryptography.rsacryptoserviceprovider.getkeypair()    @ system.security.cryptography.rsacryptoserviceprovider..ctor(int32 dwkeysize, cspparameters parameters, boolean usedefaultkeysize)    @ system.security.cryptography.x509certificates.x509certificate2.get_privatekey()    @ rsapoc.program.main(string[] args) 

i have found similar unanswered question on so, using un-managed code, whereas using managed api, both seems having same root cause.

we contacted microsoft support solution , here response got:

  1. why private key not available when code executed on server2?
    a: design. certificate stores different private key storage. while can enumerate certificates remotely, private keys cannot accessed remotely.

  2. can issue fixed giving user privileges or changes in group policy settings? a: no. doesn’t involve privileges or permission file.

  3. if not both of above can suggest suitable solution?
    a: 1. can install certificate on machines each 1 has copy of private key.
    2. can create roaming domain user. roaming certificate situation private keys can roamed between machines. roaming profiles located on server, when user logs on, temporary copy of profile (including private key) created.
    3. use third party cryptographic provider. there cryptographic providers allow remote private key access , cryptographic operations.


Comments

Popular posts from this blog

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -