Base64 is ASCII encoding. When you encode binary data with a Base64 algorithm, the output is ASCII bytes. That is the main purpose of Base64. Here is some code to prove it:
import javax.xml.bind.DatatypeConverter;
import java.nio.charset.Charset;
import org.apache.commons.codec.binary.Base64;
public class Main {
public static void main(String[] args) {
String s = "我愛我的狗.";
byte[] base64Encoded = Base64.encodeBase64(s.getBytes());
Charset ascii = Charset.forName("US-ASCII");
String asciiEncoded = new String(base64Encoded, ascii);
System.out.println(DatatypeConverter.printHexBinary(base64Encoded));
System.out.println(DatatypeConverter.printHexBinary(asciiEncoded.getBytes()));
}
}
The Apache Base64 encoder you are using is reliable. What is the C decoder your are using? How are you transferring the data from Java to C? Are you sure you are "receiving" the same bytes on the C side?
One possible problem is that you are using different versions of the Base64 encoding algorithm to encode/decode your bytes. There are many variants of Base64. See this article, for example.
Is it possible you have "safe URL encoding" enabled/disabled in one or the other encoder/decoder?