base64 decode in C

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

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_set_flags(bmem, BIO_FLAGS_BASE64_NO_NL);
    BIO_read(bmem, buffer, length);
    BIO_free_all(bmem);
    return buffer;
}

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.
Returns nothing.

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.
"AAAAB3NzaC1yc2EAAAADAQABAAABAQC/KdcFv09+f+tJK9IZ8I+L0zG7dUINClI5v8FlHJsBPSM3DDO2DpwIg/KqZKCRH9y6lEO+QAJt2DTEq/LBZcBUCdeiX1TXPFRorX+VdZigj7av/S/UHkq2EH6hfkJB3oLA5ZOZioMOAuDv1ng/DE4pRBr+KZ2oVhGjf3wa0hWi21vTZqb3s7vh+bPf6C2eUmAQJKHvFhtBK8Xx7FxN0b7igsGbk7ObwcItfMxdzkMvuiuU/UnthFVpa8wZIObFDi3MxJuf3/R+h6R1lFMvEIrU6CWRupS7Pqkm4X3qWQfhAWbdgdbD5KAk5JLA2eWIPQQA5Uay5CeH+GXz8gCa4zaz"

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.

--Prashant
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mta.openssl.org/pipermail/openssl-users/attachments/20150318/ff926df2/attachment.html>


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux