I need to use base64 encoded credentials for an API call. From a web UI interface for the API I have gotten the credentials in base64 encoded form. For the sake of showing my issue I have saved the credentials to a file creds
and the base64 encoded credentials from the web ui in a file creds64
.
Then, running the script below:
#!/bin/bash
CREDS=$(cat creds)
BASE64_CREDS=$(cat creds64)
if [[ $CREDS == $(base64 -d creds64) ]]; then
echo "the original credentials were the same as the decoded base64 credentials"
else
echo "the original credentials were NOT the same as the decoded base64 credentials"
fi
if [[ $(base64 creds) == $BASE64_CREDS ]]; then
echo "the encoded original credentials were the same as the base64 credentials"
else
echo "the encoded original credentials were NOT the same as the base64 credentials"
fi
The resulting output is
the original credentials were the same as the decoded base64 credentials
the encoded original credentials were NOT the same as the base64 credentials
I don't understand how the base64 decoded credentials can equal the "plain" credentials, but comparing the result of base64 creds
with the already encoded credentials can be not equal.
What am I misunderstanding here?