Issues with the Base64 encoding zero fill padding pattern

I got some issues with the zero fill patterns on an Arduino esp32 skatch for a rest server. I want to use the basic HTTP authentification header, but the base64 encoder that i've found for Arduino esp32 use a different pattern ('A' instead of '=' and 'A=' instead of '==').
Did someone know a library that use the same specs as the oldschool HTTP authentification?
Or knows a solution without aditional workaround? Because that is superfluous if the encoder can be implemented with the required specifications.

I've used this Base64 library in the past for encoding binary as printable text. A quick look at the source code suggests that it uses '='. My project was for a different purpose than HTTP but the library may be what you are looking for.

Thanks, I will embed it and try it out. :slight_smile:

Unfortunately it was taken from the same code base and the code in lines 55 to 69 is a bit confused:

55  if(i){
56          for(uint8_t j = i; j < 3; j++){
57              a3[j] = '\0';
58          }
60          a3to4(a3, a4);
62          for(uint8_t j = 0; j < i + 1; j++){
63              *output++ = alphaTable[a4[j]];
64          }
66          while(i++ < 3){
67              *output++ = '=';
68          }
69      }
72  }

Fullfilling a3 with zeros (in lines 56 to 58) results in some useless 'A's being added to the output.
(alphaTable[0] = 0x41 = 65 = ASCII index for A).
This is because that increasing by 1 in line 62 results in an addition of surely one 'A' - in some cases two 'A's - to the output.
The padding with equal signs, which is actually exclusively required, is additionally executed (lines 66 to 69).

User: 'admin', password: 'esp32'
www-authorization: 'basic YWRtaW46ZXNwMzI='
BASE64::encode generates 'YWRtaW46ZXNwMzIA'

User: 'admin', password: 'esp3'
www-authorization: 'basic YWRtaW46ZXNwMw=='
BASE64::encode generates 'YWRtaW46ZXNwMwA='

User: 'admin', password: 'esp'
www-authorization: 'basic YWRtaW46ZXNw'
BASE64::encode generates 'YWRtaW46ZXNwAA=='

This looks like it was done right:

But it's a pure C++ library...

Since I have not found an Arduino Base64 [en|de]coder, which coding standard Base64 strings, can be integrated out of the box and meets my ideas of lightweight, I scripted a new lib: