Base64 in Dart

How to encode and decode Base64 in Dart — with copy-paste examples and a live converter to check your output.

Dart's built-in dart:convert library provides base64Encode/base64Decode along with a base64Url codec for the URL-safe alphabet.

Encode to Base64 in Dart

Dart
import 'dart:convert';

final encoded = base64Encode(utf8.encode("Hello, World!"));

Decode Base64 in Dart

Dart
import 'dart:convert';

final text = utf8.decode(base64Decode(encoded));

Notes & gotchas

Use base64Url.encode/base64Url.decode for the URL-safe alphabet (used by Flutter apps for tokens and deep links). base64Decode throws a FormatException on malformed input, so wrap it in try/catch.

Try it live

0 characters

Base64 in Dart — FAQ

How do I Base64 encode a string in Dart?+

Use the code shown above. Use base64Url.encode/base64Url.decode for the URL-safe alphabet (used by Flutter apps for tokens and deep links). base64Decode throws a FormatException on malformed input, so wrap it in try/catch.

How do I decode Base64 back to text in Dart?+

Use the decode snippet above. Base64 decoding is lossless, so you get the exact original bytes back; decode them with UTF-8 to recover text.

Is Base64 encoding the same across programming languages?+

Yes. Base64 is a standard (RFC 4648), so a string encoded in one language decodes correctly in any other. Only the API differs, not the output.

Does Base64 secure my data?+

No. Base64 is an encoding, not encryption — anyone can decode it. Never use it to protect secrets.