export public key in pkcs8 format

Hi,

I'm creating private/public key and try to export the public key to pkcs8 format with no success. I'm only able to get it in pkcs1 format.

Creation of keys are done with SecKeyCreateRandomKey. I then use SecKeyCopyPublicKey to get the public key. Finally I use SecItemExport to get it to the desired format.

When using it with parameter kSecFormatWrappedPKCS8, it failed with error errSecParam.

I'm able to get it successful only like that:

SecItemExport(m_public_key, kSecFormatOpenSSL, kSecItemPemArmour, nullptr, &data); 

Any idea why using kSecFormatWrappedPKCS8 failed ?

Also, how can I convert it from PKCS1 to PKCS8 ?

Thanks, Tal

Answered by taloz in 696645022

I found out that if I use SecItemExport with parameter kSecFormatBSAFE it give me PKCS8 format

Accepted Answer

I found out that if I use SecItemExport with parameter kSecFormatBSAFE it give me PKCS8 format

export public key in pkcs8 format
 
 
Q