how to get private key from PEM file?

后端 未结 6 762
迷失自我
迷失自我 2020-11-27 02:51

i have a .PEM file that includes public key and a private key for SSL data transfer like this:

-----BEGIN RSA PRIVATE KEY-----
      private key data
-----EN         


        
6条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-27 03:28

    I don't know .NET (but Java) but the answer should be the same.
    Your pem file contains both the certificate and private key.
    This is a usual export in OpenSSL.
    To instantiate an object of X509Certificate in Java you would use only the part of the file that says:

    -----BEGIN CERTIFICATE-----
    certificate data
    -----END CERTIFICATE-----

    It should be the same in .NET.
    Just load the file and load that part of PEM.

    Do the same for private key.
    In java you would use the corresponding object i.e. PrivateKey to load it.
    Use the appropriate for .NET

提交回复
热议问题