Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Encoding fails to create a universally decodable base64 string #22

Open
shamas opened this issue Apr 11, 2018 · 3 comments
Open

Encoding fails to create a universally decodable base64 string #22

shamas opened this issue Apr 11, 2018 · 3 comments
Labels

Comments

@shamas
Copy link

shamas commented Apr 11, 2018

Example:
Inp: fdsfdsafdsaff|https://cdsf.fdsf.fdsfsd.com/rep|https://lfdjsfjsdfj.fdskfjdsk.com/license

Outputs:
ZmRzZmRzYWZkc2FmZnxodHRwczovL2Nkc2YuZmRzZi5mZHNmc2QuY29tL3JlcHxodHRwczovL2xmZGpzZmpzZGZqLmZkc2tmamRzay5jb20vbGljZW5zZQ

Testing
Decoding:
$ echo | base64 -D

Outputs:
fdsfdsafdsaff|https://cdsf.fdsf.fdsfsd.com/rep|https://lfdjsfjsdfj.fdskfjdsk.com/licens

Expected
The common additional characters at the end of the base64 encoded string should be present, this prevents the loss of the last character when it is read by tools that aren't this library.

@shamas
Copy link
Author

shamas commented Apr 16, 2018

@allentc
Copy link

allentc commented Dec 11, 2018

This implementation of URL safe Base64 is flawed and will yield invalid encoded values due to missing padding characters. The "general case" language should be assumed in this work.

RFC 4648 The Base16, Base32, and Base64 Data Encodings

3.2.  Padding of Encoded Data

   In some circumstances, the use of padding ("=") in base-encoded data
   is not required or used.  In the general case, when assumptions about
   the size of transported data cannot be made, padding is required to
   yield correct decoded data.

   Implementations MUST include appropriate pad characters at the end of
   encoded data unless the specification referring to this document
   explicitly states otherwise.

   The base64 and base32 alphabets use padding, as described below in
   sections 4 and 6, but the base16 alphabet does not need it; see
   section 8.

@empjustine
Copy link

universally decodable base64 string

No such thing exists, RFC 4646 declares 2 incompatible dialects of base64:

The gnu util base64 -D is only capable of handling "Base 64 Encoding", and will choke on "Base 64 Encoding with URL and Filename Safe Alphabet" or "base64url", what this library uses.

You can't use base64 -D to decode the output from this library.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants