Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

openSSL: difference between PEM_write_RSAPublicKey and PEM_write_RSA_PUBKEY

In the openssl library I can see two methods to write a public Key to a file:

int PEM_write_RSAPublicKey(FILE *fp, RSA *x);
int PEM_write_RSA_PUBKEY(FILE *fp, RSA *x);

In the documentation i can see:

The RSAPublicKey functions process an RSA public key using an RSA structure. The public key is encoded using a PKCS#1 RSAPublicKey structure.

The RSA_PUBKEY functions also process an RSA public key using an RSA structure. However the public key is encoded using a SubjectPublicKeyInfo structure and an error occurs if the public key is not RSA

But i don't understand what is

SubjectPublicKeyInfo

And what are the fundamentals differences between the 2 methods!

like image 605
darkheir Avatar asked Nov 04 '22 09:11

darkheir


1 Answers

SubjectPublicKeyInfo - ASN1 structure for public keys which is described in rfc 3280(Internet X.509 Public Key Infrastructure). This format in fact contains id of the public key algorithm and the public key itself. And in this case this public key is formatted according to the pkcs1 standard. So X.509 format is more high level format, it describes not just RSA public key but public key in general.

like image 155
SkySurfer Avatar answered Nov 08 '22 07:11

SkySurfer