How to Fix UTF-8 and EUC-KR Mojibake After Base64 Decoding
Base64 encodes raw bytes—not character sets. When a legacy ERP or Korean/Japanese gateway encodes EUC-KR or Shift_JIS bytes into Base64, standard UTF-8 decoders render unreadable replacement diamonds.
Why Valid Base64 Turns Korean, Japanese & Chinese Text Into Mojibake
Understand why Base64 operates strictly on raw 8-bit octets and how non-fatal UTF-8 decoding destroys legacy EUC-KR and Shift_JIS strings.
Read full technical details
A pervasive myth assumes Base64 always represents UTF-8 strings. In reality, RFC 4648 encodes arbitrary 8-bit byte streams without carrying character-set metadata. When a Korean settlement system, legacy banking mainframe, or Japanese logistics gateway serializes text in EUC-KR (CP949), Shift_JIS, GB18030, Big5, or Windows-1251 and Base64-encodes those bytes, the resulting Base64 string is 100% standards-compliant.
Corruption strikes during decoding: conventional web utilities pass decoded octets straight into non-fatal UTF-8 decoding (TextDecoder("utf-8", { fatal: false })), silently replacing unmatched Hangul, Kana, or CJK byte pairs with U+FFFD replacement diamonds () or scrambled Latin symbols.
Worse yet, copying or re-encoding that broken UTF-8 preview permanently overwrites the original codepage bytes with EF BF BD, making downstream recovery impossible.
Fatal UTF-8 Probing & Automatic Legacy Codepage Scoring
Use fatal TextDecoder validation to catch invalid UTF-8 instantly and score regional codepages for automatic, lossless recovery.
Read full technical details
The reliable recovery pattern begins with new TextDecoder("utf-8", { fatal: true }). Any non-ASCII legacy byte sequence outside valid UTF-8 multi-byte bit patterns throws a TypeError immediately—serving as an unambiguous signal to probe regional codepages rather than emitting replacement diamonds.
Base64Doc runs fatal decoders across EUC-KR/CP949, Shift_JIS, GB18030, Big5, and Windows-1251 inside its Web Worker, scoring valid script coherence (Hangul Syllables, Kana/Kanji ranges, CJK Unified Ideographs, and Cyrillic blocks) to surface the crisp recovered text plus a "Compare Garbled UTF-8" toggle for debugging upstream tickets.
For greenfield APIs you control, standardize on UTF-8 bytes before Base64 encoding so cross-language clients decode uniformly without charset guessing.
Handling Mixed Gzip + Legacy Codepages Inside Webhook Logs
Decompress RFC 1952 1F 8B streams first before running fatal UTF-8 validation so compressed Korean or Japanese receipts recover cleanly.
Read full technical details
Enterprise messaging hubs frequently layer Gzip compression (1F 8B 08, H4sI... in Base64) around legacy EUC-KR or Shift_JIS JSON bodies to save bandwidth. Running text decoders directly on compressed octets fails immediately; always gunzip the binary stream first, then pass the inflated byte slice through fatal UTF-8 validation and legacy codepage scoring.
Once recovered inside Base64Doc’s /gzip-base64-decode or /base64-decode workbench, copy the clean UTF-8 result or toggle "Compare Garbled UTF-8" to document the exact upstream charset mismatch.
Production Reference Code
// Strict UTF-8 check followed by EUC-KR fallback (supported natively in modern TextDecoder)
function decodeLegacyBase64Text(bytes) {
try {
return { charset: 'utf-8', text: new TextDecoder('utf-8', { fatal: true }).decode(bytes) };
} catch {
return { charset: 'euc-kr', text: new TextDecoder('euc-kr', { fatal: true }).decode(bytes) };
}
}Step-by-Step Local Workflow
Decode Base64 to Raw Uint8Array Bytes
Avoid routing intermediate Base64 outputs through Latin1 strings or legacy escape() hacks before checking byte encoding.
Run Fatal UTF-8 Validation First
Invoke new TextDecoder("utf-8", { fatal: true }); any thrown TypeError proves the payload uses a non-UTF-8 encoding.
Score Regional Legacy Codepages
Evaluate EUC-KR/CP949, Shift_JIS, GB18030, Big5, and Windows-1251 with fatal decoders and script-range heuristics.
Confirm Legible Output Before Re-Saving
Verify readable characters before converting decoded receipts to UTF-8 or saving clean text files.
Test Directly in Browser Workbench
Frequently Asked Questions
Why does Korean text from a legacy API turn into question-mark diamonds after Base64 decoding?
The upstream system encoded EUC-KR or CP949 bytes instead of UTF-8, and standard web decoders force non-fatal UTF-8. Switching the decoder to EUC-KR restores the Hangul immediately.
Can one Base64 string be both valid UTF-8 and valid EUC-KR?
Only for pure 7-bit ASCII bytes (0x00–0x7F), which share identical byte values; multi-byte Korean Hangul in EUC-KR almost always fails strict UTF-8 bit-prefix checks.
Does browser TextDecoder support euc-kr, shift_jis, and gb18030 natively?
Yes, the WHATWG Encoding Standard implemented in Chrome, Firefox, Safari, and Node.js supports utf-8, euc-kr, shift_jis, gb18030, big5, and windows-1251 natively.
Why should I avoid JavaScript escape(atob(...)) hacks for UTF-8?
Deprecated escape/unescape tricks fail on malformed sequences and cannot decode legacy Asian codepages; TextDecoder with Uint8Array is standard and safe.
Can I test EUC-KR or Gzip + EUC-KR decoding live on Base64Doc?
Yes, load Showcase Case 4 on the home page or paste your legacy Base64 text straight into /base64-decode or /gzip-base64-decode.