Author Topic: (Chilkat.PrivateKey) -> GetRsaPem() vs SaveRsaPemFile(xx)  (Read 500 times)

Target2

  • Newbie
  • *
  • Posts: 4
  • Karma: +0/-0
    • View Profile
(Chilkat.PrivateKey) -> GetRsaPem() vs SaveRsaPemFile(xx)
« on: November 30, 2017, 09:40:27 AM »
hi I have this esample :

Code: [Select]
            ....
            string privateKeyXml = rsa.ExportPrivateKey();
            Chilkat.PrivateKey privKey = new Chilkat.PrivateKey();
            bool success = privKey.LoadXml(privateKeyXml);
            string prkp = privKey.GetRsaPem();
            success = privKey.SaveRsaPemFile("privateKey.pem");

Why the string privKey.GetRsaPem() has a different value out of that generated in the file with privKey.SaveRsaPemFile("privateKey.pem");?

example :

privKey.GetRsaPem() give this string :

Code: [Select]
-----BEGIN RSA PRIVATE KEY-----
MIIBOgIBAAJBANM3kMM0vH/6lvX1kUsbmJmACBBvYdjyoUOUiDh2Vfu5LsayUJeQ
5bdY7VmxXn78L/mqmXTPDbsIb4hbvU6qJlcCAwEAAQJBAMZPOV/ON92BDhPIiK4Y
LuKQTwH/UcM7qyWkY3F/yaMYufGhznshKssGBgNNJom66BRK90OSY/lVYQFY8BJy
rIECIQD2LZR/9wMLzqqu62wAor6SbAfDnoka1ztxq08hKMbzJwIhANuk5l06uYcd
jE6Z2/M9xZ70Wlh/WLS3qUTLwBoYZXFRAiBzwydLrXpPORXmP2qAOgdnj0lvYcOT
TZb0ctw4+ZXkjQIgOozEk8mZtzjbNACzry2iRnMgukKIJPRofNxLgylJsWECIGD8
Q5HxaHfX0eOqir22fgfQMnRfEoWxYUirUcCOYARg
-----END RSA PRIVATE KEY-----

privKey.SaveRsaPemFile("privateKey.pem"); -> give the file whit this content :

Code: [Select]
-----BEGIN PRIVATE KEY-----
MIIBVAIBADANBgkqhkiG9w0BAQEFAASCAT4wggE6AgEAAkEA0zeQwzS8f/qW9fWR
SxuYmYAIEG9h2PKhQ5SIOHZV+7kuxrJQl5Dlt1jtWbFefvwv+aqZdM8NuwhviFu9
TqomVwIDAQABAkEAxk85X8433YEOE8iIrhgu4pBPAf9RwzurJaRjcX/Joxi58aHO
eyEqywYGA00mibroFEr3Q5Jj+VVhAVjwEnKsgQIhAPYtlH/3AwvOqq7rbACivpJs
B8OeiRrXO3GrTyEoxvMnAiEA26TmXTq5hx2MTpnb8z3FnvRaWH9YtLepRMvAGhhl
cVECIHPDJ0utek85FeY/aoA6B2ePSW9hw5NNlvRy3Dj5leSNAiA6jMSTyZm3ONs0
ALOvLaJGcyC6Qogk9Gh83EuDKUmxYQIgYPxDkfFod9fR46qKvbZ+B9AydF8ShbFh
SKtRwI5gBGA=
-----END PRIVATE KEY-----

Regards
« Last Edit: November 30, 2017, 01:42:22 PM by Target2 »

Chilkat

  • Administrator
  • Full Member
  • *****
  • Posts: 103
  • Karma: +6/-0
    • View Profile
Re: (Chilkat.PrivateKey) -> GetRsaPem() vs SaveRsaPemFile(xx)
« Reply #1 on: December 02, 2017, 01:24:27 PM »
GetRsaPem returns the RSA key using PKCS1, whereas SaveRsaPemFile uses PKCS8.  Both are correct, just slightly different internal formats.

Both GetRsaPem and SaveRsaPemFile are deprecated. 

The GetRsaPem method is replaced by the GetPkcs1Pem and GetPkcs8Pem methods (given that PrivateKey may contain a non-RSA key).
Likewise, the SaveRsaPem file should be replaced by either SavePkcs1File or SavePkcs8File.