Fix base64 encoding bugs.

Add test cases to verify encoding/decoding non-ASCII data.