Question

I'm trying to decode base64-encoded string with openssl. However, it works only 4 times out of 5.

Decoded string should always be 64 chars long. BIO_read() always returns 64. However, sometimes returned buffer is shorter than 64!

Any ideas what is wrong? How can i always get the correct string?

Was it helpful?

Solution

Are you using str[n]cpy? You can't! Base64 encoded data can contain null characters, which C string processing functions interpret as end-of-string.

Use memcpy instead of str[n]cpy, memcmp instead of strcmp, etc. These functions require you to know your data size, but I believe that you do know it.

Also if you're not very confident about C-style strings and such, there's plenty of information to be found about the topic here.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top