Intuition and OpenSSL: exporting RSA keys

Few things are less intuitive in this world than exporting private and public RSA keys in OpenSSL: at first sight one could think that the right functions are PEM_write_bio_RSAPrivateKey and PEM_write_bio_RSAPublicKey. Everything compiles, the outputs are consistent and it seems that everything is going well, but soon one discovers there is no way to make the program fail to use the public key. The problem is that the function to be used is PEM_write_bio_RSA_PUBKEY!

Related links