I have a function that parses a private RSA key using openssl's d2i_RSAPrivateKey function. I am finding that this succeeds with certain keys, but not others, even though all of these keys are PEM-encoded RSA keys. I generated my own signed public and private key, like this:
openssl req -x509 -newkey rsa:2048 -keyout key.pem -out cert.pem -days 36500 -nodes -outform PEM
I combined key.pem and cert.pem into a single file, combined.pem, and verified that I can parse the file with openssl's x509 and rsa commands:
openssl x509 -inform PEM -modulus -in combined.pem
Modulus=B59A...
openssl rsa -inform PEM -modulus -in combined.pem
Modulus=B59A...
But d2i_RSAPrivateKey silently fails to parse this file in code, returning an error code without printing anything. I know I'm using d2i_RSAPrivateKey correctly, because it works on a different public/private cert file. Can anyone tell why it can't parse the file I'm creating here on the command line?