[openssl-users] base64 decode in C
prashant at apigee.com
Wed Mar 18 07:36:40 UTC 2015
Most likely this has been answered before, please bear with me.
I'm trying to use the base64 decode function in C. Below is the function.
char *b64_decode(unsigned char *input, int length)
BIO *b64, *bmem;
char *buffer = (char *)malloc(length);
memset(buffer, 0, length);
b64 = BIO_new(BIO_f_base64());
bmem = BIO_new_mem_buf((void*)input, length);
bmem = BIO_push(b64, bmem);
BIO_read(bmem, buffer, length);
This works well for simple b64 encoded strings like "hello world!" etc. But
when I want to b64 decode the contents of a SSH public key, it fails.
What I'm trying to get to is the SSH public key fingerprint which is the
MD5 hash of the base64 decoded part of the public key.
This decodes fine.
"dGhpcyBpcyBhd2Vzb21lCg==" : "this is awesome"
This does not.
What I'm I doing wrong ?
Btw in the command line both decode. Using "echo string | openssl enc
-base64 -d -A"
Any help appreciated.
Thanks in advance.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the openssl-users