OK. I do not know what is your current testing code.
But looking on first post I think you are converting too much.
Did you tried Alyssons method of decode?
cl_http_utility=>decode_x_base64( ).
It has direct output in xstring so you have binary data right there. Without other conversions which might corrupt file data.