Base64 Encoding in D Programming Language
Our first example demonstrates base64 encoding and decoding in D. D provides built-in support for base64 encoding/decoding.
In this D code, we use the std.base64
module which provides both standard and URL-compatible base64 encoding and decoding.
To run the program, save it as base64_encoding.d
and use the D compiler:
The string encodes to slightly different values with the standard and URL base64 encoders (trailing +
vs -
) but they both decode to the original string as desired.
In D, we use Base64.encode
and Base64.decode
for standard base64 encoding and decoding, and Base64URL.encode
and Base64URL.decode
for URL-compatible base64 encoding and decoding. The cast
keyword is used to convert between string and ubyte[] types as required by the encoding and decoding functions.