MadScientist
MadScientist

Reputation: 565

Encryption routine adds %3D to the end of ouput

I have an encryption that I use for some minor security but I am noticing that the out always seems to have %3D at the end of the encrypted string and I am not sure why.

private static function encrypt($str, $key)
{
    $result = null;
    for ($i = 0; $i < strlen($str); $i++) {
        $char = substr($str, $i, 1);
        $keyChar = substr($key, ($i % strlen($key)) - 1, 1);
        $char = chr(ord($char) + ord($keyChar));
        $result .= $char;
    }

    return urlencode(base64_encode($result));
}

I cannot see anything glaring in there.

When decrypting the strings there are no errors when I manually remove the extra %3D at the end of the string.

so

bnNMTXc0Sjc%3D

AND

bnNMTXc0Sjc

Will both decrypt the same. I just want to clean up the encrypted strings to not have the extra chars at end.

Thanks

Upvotes: 3

Views: 6795

Answers (1)

exussum
exussum

Reputation: 18568

Its the URL encode with the = at the end of the base 64 it won't cause an issue Why does a base64 encoded string have an = sign at the end

Upvotes: 4

Related Questions