base64 decode in C

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

 



> From: openssl-users On Behalf Of Prashant Bapat
> Sent: Wednesday, March 18, 2015 03:37

> I'm trying to use the base64 decode function in C. <snip>

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

It returns pointer to a buffer containing the pubkey, but no indication of 
the length. You don't show the caller, but if the caller tries to treat it as a 
C string with strlen()fputs() etc that won't work because it isn't a C string.
A C string can't contain any zero-bits aka null byte, and SSH pubkey contains 
many of them; it even starts with *three* consecutive nulls, which 
makes it appear to be empty if treated as a C string.

Use the length returned from (successful) BIO_read (b64bio,...).

> This decodes fine. 
> "dGhpcyBpcyBhd2Vzb21lCg=="  : "this is awesome"

Actually that decodes as "this is awesome" PLUS A NEWLINE, or in 
C source notation "this is awesome\n". Yes that matters. 




[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