Why can't Dart decode base64 from Crystal?

Why does Dart produce the error "invalid character at position 61" with base64 from Crystal Lang?

Upvotes: 0

Views: 203

Answers (1)

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

Upvotes: 5

Related Questions