An error occurred while using the d2i_RSAPublicKey function.

An error occurred while using the d2i_RSAPublicKey function.

I am getting RSA publickey from the server.
I need to extract the modulus and public exponent from the key to do the RSA
operation.
I have to solve with C language code, not shell command.
I have written the following test code, and an error has occurred in the
d2i_RSAPublicKey function.
A null pointer is returned as the result of the d2i_RSAPublicKey function.

Re: An error occurred while using the d2i_RSAPublicKey function.

> On Jun 9, 2018, at 8:38 PM, Sangsub <[hidden email]> wrote:
>
> I have written the following test code, and an error has occurred in the
> d2i_RSAPublicKey function.
> A null pointer is returned as the result of the d2i_RSAPublicKey function.

Your input data is not a PKCS#1 RSA public key as understood by
d2i_RSAPublicKey(). Rather, it is an X.509 SPKI public key,
as understood by d2i_RSA_PUBKEY(), or, more generally, d2i_PUBKEY().

Re: An error occurred while using the d2i_RSAPublicKey function.

Actually, I'm begginer so I don't know well.
You said that the my input data is not a PKCS # 1 public key type.

How do I distinguish between a PKCS # 1 type or an X.509 SPKI Public Key?

and it seems to work well when you use d2i_RSA_PUBKEY as you told me.
I would like to ask you one more question.
What is the modulus value of the key I entered?
The modulus values I have come up with the above code are as follows.

Re: An error occurred while using the d2i_RSAPublicKey function.

> On Jun 9, 2018, at 11:25 PM, Sangsub <[hidden email]> wrote:
>
> Actually, I'm begginer so I don't know well.
> You said that the my input data is not a PKCS # 1 public key type.
>
> How do I distinguish between a PKCS # 1 type or an X.509 SPKI Public Key?

You should not have to distinguish. The key type will be the same
for a particular method of obtaining the key. In this case, the
key will almost surely always be SPKI. You've not explained how
you're obtaining the keys, why it is safe to assume they're RSA
and not (say) ECDSA keys, or why you're looking to work with the
public exponent and modulus, rather than use the existing OpenSSL
signature verification functions.