X509Certificate - Keyset does not exist

前端 未结 6 1016
北海茫月
北海茫月 2020-12-05 04:01

I have a WinForms application that consumes a WCF, and pass as a parameter to a function a certificate:

mySvcClient.SendDocument(cert.Export         


        
6条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-05 04:58

    I was facing the same issue, and I don't know how(shame on me), but it worked:

    var certificate = new X509Certificate2(filePath, password,
        X509KeyStorageFlags.MachineKeySet | X509KeyStorageFlags.Exportable | X509KeyStorageFlags.PersistKeySet);
    
    certificate.PrivateKey; // before: error "KeySet does not exist"!
    
    using (certificate.GetRSAPrivateKey()) { } // pure black magic
    
    certificate.PrivateKey; // after: just works! lol
    

    I hope someone can answer this mystery.

提交回复
热议问题