You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
(1) I confirm that the above fix [ int inputLen = sizeof(input)-1 ] is needed and does work. I tried to use this library on ESP8266 smtp to smtp2go. Without the fix, the smtp2go server rejects the base64 encrypted userid and password, but with the fix the server accepts both and the email communication completes successfully.
(2) Note that there is a conflict with other base64.h files auto installed with esp8266 core library at least on the Arduino IDE 1.6.7 I am using. To use this library the base64.h and base64.cpp must be located in the same directory as the main.ino file and the include statement must be changed to #include "Base64.h" instead of #include <Base64.h>.
(3) And finally, the file base64.cpp must be modified as follows:
change #include <avr/pgmspace.h> to #include <pgmspace.h>
Another issue is that the length of the output char array must be increased by 1 because the library adds an extra \0 at the end (string termination).
See my #12 (comment) and pull request #23
In the example code... using it to authenticate a RESTAPI, I ran into a problem, but fixed it by decreasing the input size by 1.
// encoding
char input[] = "username:password";
int inputLen = sizeof(input)-1; <== Need to do this (most likely the code is processing the \0)
int encodedLen = base64_enc_len(inputLen);
char encoded[encodedLen];
// note input is consumed in this step: it will be empty afterwards
base64_encode(encoded, input, inputLen);
Serial.println(encoded);
will produce the following:
dXNlcm5hbWU6cGFzc3dvcmQ=
Here is what Apache will provide in the header for basic authentication... They match, but without decreasing the inputLen by 1, they will not.
Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ=
The text was updated successfully, but these errors were encountered: