Dart - Base64 string is not equal to python Dart - Base64 string is not equal to python dart dart

Dart - Base64 string is not equal to python


You explicit asked Python for replacing all + characters with - in the base64 encoded string, because you have used the urlsafe_b64encode variant! The documentation says:

base64.urlsafe_b64encode(s)

Encode bytes-like object s using the URL- and filesystem-safe alphabet, which substitutes - instead of + and _ instead of / in the standard Base64 alphabet, and return the encoded bytes. The result can still contain =.

If you want the same string as Dart produces, just use simply encodebytes for Python3 or encode for Python 2.


Dart has a URL safe version of Base 64 encode, like Python.

Change

var _base64 = base64Encode(_bytes);

to

var _base64 = base64UrlEncode(_bytes);