[openssl-users] Facing issue while reading RSA private key (DER format)
Matt Caswell
matt at openssl.org
Wed May 23 13:19:07 UTC 2018
On 23/05/18 12:10, Ruchi Tyagi wrote:
> Hi,
>
>
>
> I am working on a project where we are trying to Replace RSA Bsafe
> crypto C library with openssl. I have a RSA key pair (attaching the key
> files) generated using RSA Bsafe library.
>
> I am able to read the public key using the below call
>
>
>
> rsa = d2i_RSA_PUBKEY(NULL, &public_key_bytes, public_key_length);
RSA public keys typically come in either PKCS#1 format or
SubjectPublicKeyInfo format. You need to ensure you use the correct
function for the format. Your public key is in SubjectPublicKeyInfo
format, and this is the correct function for reading that format - so it
succeeds.
>
>
>
> but while decryption , I am getting NULL “rsa” .
>
>
>
> rsa = d2i_RSAPrivateKey(NULL, &p, size);
RSA private keys typically come in either traditional or PKCS#8 format.
Your private key is in PKCS#8 format, but this function is for reading
traditional format keys - hence the failure.
If you use the function d2i_AutoPrivateKey() then it will automatically
try to detect the format. It returns an EVP_PKEY *object which is the
preferred internal object for working with public/private keys. If you
must have it as an "RSA *" object you can do that with
EVP_PKEY_get1_RSA() (or EVP_PKEY_get0_RSA() if you don't want to up the
ref count on the RSA object).
Matt
>
>
>
>
>
> It seems that I am not using the right call or missing something.
>
>
>
> Please help me in resolving this issue.
>
>
>
> Thanks & Regards,
>
> Ruchi
>
>
>
> _______________________________________________
> osf-contact mailing list
> To unsubscribe: https://mta.openssl.org/mailman/listinfo/osf-contact
>
More information about the openssl-users
mailing list