magiclen / base64-url

Base64 encode, decode, escape and unescape for URL applications.
MIT License
9 stars 0 forks source link

Fails to correctly encode "aswf!@#$%^&*()" #1

Closed BafDyce closed 5 years ago

BafDyce commented 5 years ago
base64_url::encode("aswf!@#$%^&*()")

returns "YXN3ZiFAIyQlXiYqKCk"

Attempting to decode this with Linux' base64 binary fails:

$ echo "YXN3ZiFAIyQlXiYqKCk" | base64 -d
aswf!@#$%^&*()base64: invalid input

This is the correct base64 encoding (trailing '='!):

$ echo -n 'aswf!@#$%^&*()' | base64
YXN3ZiFAIyQlXiYqKCk=

The base64-crate correctly encodes the string, so I don't know where base64_url goes wrong.

magiclen commented 5 years ago

Do you know the difference between Base64-standard and Base64-url?

See https://tools.ietf.org/html/rfc4648#section-5

BafDyce commented 5 years ago

Oh, sorry. I was not aware that the trailing padding can be optional in base64-url.