come ottenere la chiave privata dal file PEM?

Ho un file .PEM che include la chiave pubblica e una chiave privata per il trasferimento di dati SSL come questo:

-----BEGIN RSA PRIVATE KEY----- private key data -----END RSA PRIVATE KEY----- -----BEGIN CERTIFICATE----- public key data -----END CERTIFICATE----- 

quando voglio caricare il file .PEM con il seguente codice:

 X509Certificate2 xx = new X509Certificate2("c:\\myKey.pem"); 

ottengo un’eccezione che dice: “Imansible trovare l’object richiesto”. , con stack completo:

 System.Security.Cryptography.CryptographicException was unhandled Message=Cannot find the requested object. Source=mscorlib StackTrace: at System.Security.Cryptography.CryptographicException.ThrowCryptographicException(Int32 hr) at System.Security.Cryptography.X509Certificates.X509Utils._QueryCertFileType(String fileName) at System.Security.Cryptography.X509Certificates.X509Certificate.LoadCertificateFromFile(String fileName, Object password, X509KeyStorageFlags keyStorageFlags) at System.Security.Cryptography.X509Certificates.X509Certificate..ctor(String fileName) at System.Security.Cryptography.X509Certificates.X509Certificate2..ctor(String fileName) at DLLTest.SSL_Test.test() in E:\Projects\DLLTest\DLLTest\SSL_Test.cs:line 165 at DLLTest.SSL_Test.Run() in E:\Projects\DLLTest\DLLTest\SSL_Test.cs:line 21 at DLLTest.Program.Main(String[] args) in E:\Projects\DLLTest\DLLTest\Program.cs:line 21 at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args) at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() at System.Threading.ThreadHelper.ThreadStart_Context(Object state) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart() InnerException: 

se scambio la posizione della sezione della chiave privata e della sezione della chiave pubblica, il codice funziona e carica i dati, e posso ottenere solo informazioni sulla chiave pubblica dall’object, ad es. IssuerName e HasPrivateKey è falso. perché? ho frainteso e sbagliato qualcosa?