← Cryptography guide

K089 / Encoding and decoding

UTF-16

UTF-16 encoding · Survey date 2026-12-05

UTF-16 represents characters using one or two 16-bit code units depending on the Unicode value.

CRYPTOGRAPHY LAB / K089

Cryptography Lab · UTF-16

Run real computations and inspect intermediate states step by step.

Educational only. Never enter real passwords or secret keys. Computation stays in your browser; input and trace values are not sent to a server. Do not use this implementation in production.

Scope: Limited implementation

UTF-16LE (no BOM)

See the scope above for fixed examples, reduced parameters and supported variants. Standard operation names and formulas are retained.

Reference ↗

Open lab →

Definition and overview
UTF-16 represents characters using one or two 16-bit code units depending on the Unicode value. Source document ↗
Classification and reversibility
Reversible character encoding/decoding scheme, distinct from encryption. Source document ↗
Key or secret requirements
Not confirmed in the survey
Operating principle and structure
BMP (U+0000–U+FFFF) uses one 16-bit code unit; supplementary planes use pairs of 16-bit units. Source document ↗
Key size, block size and parameters
LE/BE byte order and BOM are important; determine order using BOM or heuristics. Source document ↗
Security strength and recommendation
Not confirmed in the survey
Known attacks and vulnerabilities
Encoding/Unicode handling and conversion can contain vulnerabilities; implementation defects are common. Source document ↗
Standards and certification
RFC 2781, referring to ISO/IEC 10646-1 Annex Q. Source document ↗
Typical uses
Windows API, Java, Qt and other programming environments/APIs. Source document ↗
Implementations, libraries and tools
Libraries such as iconv-lite support UTF-16LE/BE/UTF-16. Source document ↗
Decryption or decoding
Detect byte order using BOM and heuristics such as spaces. Source document ↗
Advantages
Optimized to represent BMP characters with one 16-bit unit. Source document ↗
Limitations and cautions
Variable length: one or two 16-bit units per code point. Source document ↗
Distinguishing encryption, encoding and hashing
Not confirmed in the survey

Practical examples

Examples are illustrative; they are not execution-tested implementations or operational recommendations.

Example

Encode BMP characters as one unit and supplementary characters as surrogate pairs. Specify UTF-16LE/BE and BOM presence when storing or sending; decode using the same rules.

Procedure

Identify code points, encode BMP as single units and supplementary planes as pairs, specify byte order/BOM. Decode by detecting byte order, assembling units and restoring surrogate pairs. Encryption is a separate keyed operation.

Scenario

Interoperate with Windows API, Java/Qt strings or UTF-16LE/BE files/protocols. Use keyed encryption and integrity protection for secure storage and transfer.

Pitfalls and alternatives

Not encryption. Watch for BOM/order mismatches, odd byte counts, unvalidated broken surrogates and conversion differences around filters. Prefer considering UTF-8 at interoperability boundaries and use validation, normalization and strict decoding.

References