Problem with base64
$data = 'my data';
echo $encryptedData = base64_encode($data);
// Output :
bXkgZGF0YQ==
I added some more characters to the token
$encryptedData = $encryptedData . 'sdfsdfasdfsd';
echo $data = base64_decode($encryptedData);
// Output :
my data~Ç_jÇ_±
Now i got actual data + junk data. i dont want any of the data or only the data if there is any change in the token. is there any method to implement this ?
To make sure changes to the base64 encoded string can only be made by changing the
$data, you will need to add a verification token.An easy way to add such verification is by using a keyed hash whereby the key is secret:
Output:
When you receive such token, you first split on
:and then use the first part (keyed hash) to verify the contents of the second part (data). Only if it matches, you can be (relatively) sure that the data has not been tampered with.