Hi Jan,

Thanks for your reply, but OpenSSL Base64 decoding api returns NULL on passing Base64 encoded data. The code snippet is as follows:

int main(int argc, char **argv)
{
char *output = unbase64("dGVzdGVuY29kaW5nCg==", strlen("dGVzdGVuY29kaW5nCg=="));
       printf("Unbase64: %s\n", output);
       free(output);
}
char *unbase64(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(input, length);
       bmem = BIO_push(b64, bmem);
       BIO_read(bmem, buffer, length);
       BIO_free_all(bmem);
       return buffer;
}

The string "*dGVzdGVuY29kaW5nCg==*" on Base64 decoding should return "*testencoding\n*", but the above code returns *NULL*. Please let me know the cause of Base64 returning NULL.

Thanks & Best Regards,
Vinay

Jan Steffens wrote:
On Tue, Mar 1, 2011 at 7:00 AM, Vinay Kumar L
<vinaykuma...@globaledgesoft.com> wrote:
Encoding of string "testencoding" using base64 command:

#base64 data.txt > encode.txt
    data.txt -----> It contains only the string "testencoding"
    encode.txt -----> It contains encoded data
#cat encode.txt
dGVzdGVuY29kaW5nCg==

This is actually the encoding for the string "testencoding\n". Note
the trailing newline, and check what your data.txt really contains.
______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
User Support Mailing List                    openssl-users@openssl.org
Automated List Manager                           majord...@openssl.org


Reply via email to