Hi,

I'm to openssl and PKI in general and got a problem whit decrypting in my
application.
My partners provided me with two files:  publickey.x509 and publickey.pem to
find a wy to send messages between server and my client application.
So far I've dicovered that .pem files are just base64 encoded DER files, DER
is the encoding for x509 files that contain the publickey among other
information.
I have the following code:

        //Get the .pem file contents
NSString *path = [[NSBundle mainBundle] pathForResource:@"publickey"
ofType:@"pem"];
NSString * pemString = [NSString stringWithContentsOfFile:path
encoding:NSUTF8StringEncoding error:nil];
const char *base64Text = [pemString cStringUsingEncoding:[NSString
defaultCStringEncoding]];
 //Base64 decode to obtain a DER representation
char *unBase64Text = unbase64((unsigned char *)base64Text,
strlen(base64Text));
int dataLength = strlen(unBase64Text);
 //Get RSA representation so we can encode messages to send back to the
server
RSA *anRSA = d2i_RSAPublicKey(0, (unsigned char **)&unBase64Text,
dataLength);

So I stop the debugger here and notice that variable 'anRSA' is empty even
tough:

'unBase64Text = some not-understandable data'
and
'dataLength = 17'

What could am I doing wrong?
-- 
Greetings

Carlos Saldaña Garcia

Reply via email to