Skip to content Skip to sidebar Skip to footer

Dart - Base64 String Is Not Equal To Python

When I use Python to generate a base64 string that will be used in the raw key { 'raw': value } GMAIL API, sending the email occurs perfectly. But when I use Dart to generate the s

Solution 1:

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.

Solution 2:

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

Change

var _base64 = base64Encode(_bytes);

to

var _base64 = base64UrlEncode(_bytes);

Post a Comment for "Dart - Base64 String Is Not Equal To Python"