How to make Crystal base64 work in Dart

Jsilverman
1 min readAug 26, 2020

--

This is going to be a short post.

The default Crystal lang Base64 encoding won’t work in Dart or Flutter.

This is because it doesn’t use strict encoding by default, inserting newlines every 60 characters.

To Dart, these newlines are unknown characters.

So, in short, you have to use Crystal’s `Base64.strict_encode` method. This will encode without special characters.

Dart has no method to ignore the special characters so this is 100% necessary to make it work.

https://crystal-lang.org/api/0.35.1/Base64.html#strict_encode(data,io:IO)-instance-method

--

--