Skip to content

Need to reduce input length by 1 to be compatible with HTTP basic authentication #15

Open
@tbraly

Description

@tbraly

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=

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions