i generated a public/private keypair using java. Since i want to add the key to my code (not as file) i used
byte[] priv = private_key.getEncoded()
to get it as a byte array.
To get back the private key from the byte array i use
PKCS8EncodedKeySpec privateKeySpec = new PKCS8EncodedKeySpec(priv);
Decryption is working as expected.
But now i want to use that key inside a c application using openssl.
So i copied the byte array from java to c as a char[].
But i’m not able to convert this char[] into a private key to use it for decryption via RSA_public_decrypt(…)
I tried
RSA *r = d2i_RSAPrivateKey(NULL,&priv, len);
but this always return a NULL pointer
Can anyone please give me a hint on how to do this in c language?
Edit: Meanwhile i checked the error code from openssl and it says
error:0D0680A8:lib(13):func(104):reason(168)
But i don’t know whet to do with those error codes. A search on the net didn’t help yet.
Many thanks in advance.
Greetings, -chris-
Thanks to hint from srikanth yaradla i found the right direction.
Here’s how i did it:
after doing that i now can easily decrypt data i get from the java part.