How to encode text as UTF-16 Base64
- Type or paste your text into Input · text. Charset is preset to UTF-16LE.
- Copy the Base64 from Output · Base64. The Input figure shows the UTF-16 byte count, twice the length of plain English text.
- For a big-endian consumer, switch Charset to UTF-16BE.
- Swap decodes the result again for a quick check; Base64 to UTF-16 is the dedicated decoder.
UTF-16LE vs UTF-16BE
UTF-16 stores each character as one or two 16-bit code units. Little-endian writes the low byte first, big-endian the high byte first. Windows and .NET use little-endian; Java’s UTF-16 encoder and many network formats use big-endian.
| Text | UTF-16LE bytes | UTF-16LE Base64 | UTF-16BE Base64 |
|---|---|---|---|
Hi | 48 00 69 00 | SABpAA== | AEgAaQ== |
Hello | 10 bytes | SABlAGwAbABvAA== | AEgAZQBsAGwAbw== |
€ | AC 20 | rCA= | IKw= |
👋 | 3D D8 4B DC | PdhL3A== | 2D3cSw== |
Characters outside the Basic Multilingual Plane, including every emoji, take two code units called a surrogate pair. 👋 (U+1F44B) becomes D83D DC4B, which is the 4 bytes in the last row.
Since every ASCII letter is paired with a zero byte, UTF-16 Base64 of English text is dotted with A characters. An unknown string with that pattern is worth decoding as UTF-16.
Where UTF-16 Base64 is used
- PowerShell
-EncodedCommand.powershell -EncodedCommand RwBlAHQALQBEAGEAdABlAA==runsGet-Date. A frequent reason such commands fail is a script encoded as UTF-8. The PowerShell EncodedCommand tool adds the command prefix, warns about the length limit ofcmd.exeand also decodes commands found in logs. - .NET code.
Encoding.Unicodein C# is UTF-16LE, soConvert.ToBase64String(Encoding.Unicode.GetBytes(s))produces the same output as this page. - Windows data. Strings from the registry, from
NVARCHARcolumns cast to binary in SQL Server and from many Windows APIs are UTF-16LE.
Byte order marks
This tool writes no byte order mark, which is what PowerShell and most APIs want. Some libraries add one automatically:
| Source | First bytes | Base64 of Hi |
|---|---|---|
| This tool, UTF-16LE | 48 00 | SABpAA== |
Python "Hi".encode("utf-16") | FF FE 48 00 | //5IAGkA |
Java "Hi".getBytes(UTF_16) | FE FF 00 48 | /v8ASABp |
If your Base64 must match one of those, encode with an explicit byte order in code, as below.
UTF-16 to Base64 in code
import base64
base64.b64encode("Get-Date".encode("utf-16-le")).decode() # 'RwBlAHQALQBEAGEAdABlAA=='
base64.b64encode("Hi".encode("utf-16-be")).decode() # 'AEgAaQ=='
// Node.js has a little-endian codec only
Buffer.from("Get-Date", "utf16le").toString("base64"); // "RwBlAHQALQBEAGEAdABlAA=="
[Convert]::ToBase64String([Text.Encoding]::Unicode.GetBytes('Get-Date'))
Use utf-16-le rather than utf-16 in Python unless you want the BOM. More examples: Python, Node.js.
FAQ
Why does PowerShell need UTF-16LE Base64?
powershell -EncodedCommand expects the Base64 of the script’s UTF-16LE bytes, because that is how Windows stores strings internally. UTF-8 Base64 decodes to the wrong characters and the command fails. The PowerShell EncodedCommand tool builds the whole command line.
What is the difference between UTF-16LE and UTF-16BE?
The order of the two bytes in each code unit. H is 48 00 in little-endian and 00 48 in big-endian, so Hi encodes as SABpAA== or AEgAaQ==.
Will the output start with a byte order mark?
No, only the text’s own bytes are encoded. Python’s "utf-16" codec and Java’s UTF_16 charset do add one, which is why their Base64 starts with //5 or /v8.
Why is UTF-16 Base64 so long?
UTF-16 uses at least 2 bytes per character, so English text doubles in size before Base64 adds its third. Hello is 8 Base64 characters in UTF-8 and 16 in UTF-16.