BASE64 LIB Incorrect Output

I download the BASE64 LIB from GitHub - adamvr/arduino-base64: A base64 library for the arduino platform, written in C
and I refer to the sample code use the base64_encode function to encoding the text "admin:admin" .
it result "YWRtaW46YWRtaW4A".

but I go into https://www.base64encode.org/ to recheck,
It turned out to be "YWRtaW46YWRtaW4=" ?

Anyone know why?

I suspect it's getting a control character or something, or maybe the null at the end? It's got one extra char.

I presume that you are using the example code. It contains a bug.

 char input[] = "admin:admin";
  int inputLen = sizeof(input);

In this case, input is declared to be an array of characters initialized to "admin:admin". But the compiler includes the NULL character at the end as an element of the array (it has to). Therefore sizeof(input) is 12 so the base64 encoding includes the NULL as part of the string, which is why there's no "=" at the end. You could just use sizeof(input)-1 but it would be clearer what is going on if you use this instead:

 char *input = "admin:admin";
  int inputLen = strlen(input);

In this case, strlen will return the length of the string without the null and give 11. The base64 encoder will then produce the correct output.
There may be a similar problem in the decoding example.

Pete

As far as I know...

BACKGROUND
There is no single base 64 encoding. There are several encodings. Most use the lower case characters a-z, the upper case characters A-Z, and the digits 0-9 to encode 6 bits at a time (uuencode is one of the exceptions). If you have done the computation, you will see that this defines 62 of 64 characters. The encodings vary in what the other two characters are, and whether they are first or last in the set of 64 characters. The encodings also vary in the way in which padding is done in case the input is not an integer multiple of 6 bits. For more information, you may want to see Base64 - Wikipedia

SPECIFICS
admin:admin is 11 characters or 88 bits which is not an integer multiple of 6 bits. The way that padding and encoding is done on the final character could well be different in different implementations. YWRtaW46YWRtaW4A differs from YWRtaW46YWRtaW4= only in the last character. This character is an equal sign which is used as padding in some implementations.

Matching a particular encoding scheme may be important to you. If not, what is important is that your decoder can decode whatever you encoded.

Good Luck!

This base64 library encodes the "admin:admin" string correctly (ending with '=') if you tell it the correct length of the string, which is 11 characters. If you tell it is 12 characters long, which is what the library's example code does, it will not give the required result.

Pete

el_supremo:
if you use this instead:

 char *input = "admin:admin";

int inputLen = strlen(input);



In this case, strlen will return the length of the string without the null and give 11. The base64 encoder will then produce the correct output.
There may be a similar problem in the decoding example.

Pete

Thank you very much,It's work !