"CND0311J4S68CCU Ver. F.0BHPQOEM - f"
encoded as base64:
Q05EMDMxMUo0UzY4Q0NVIFZlci4gRi4wQkhQUU9FTSAtIGY1
Maybe something else adds 1 to the end, because
echo base64_decode("Q05EMDMxMUo0UzY4Q0NVIFZlci4gRi4wQkhQUU9FTSAtIGY");
gives you what you are looking for. And something adding it actually System.Web.HttpServerUtility.UrlTokenEncode . The problem is the following ( from MSDN ):
This ( System.Web.HttpServerUtility.UrlTokenEncode ) does not use standard encoding. It encodes the characters - and _, which are standard. It also removes the = signs. But instead of just deleting them (they are not needed to decode the string), he replaces them with a digit (0, 1, 2) indicating the number = of characters that were deleted.
So go ( Demo ):
<?php $urltoken = "Q05EMDMxMUo0UzY4Q0NVIFZlci4gRi4wQkhQUU9FTSAtIGY1"; echo urltoken_decode($urltoken); function urltoken_decode($token) { return base64_decode(substr($token, 0, -1)); }
The function is pretty crude and can be improved to actually deal with it more specifically ( Demo2 ):
function urltoken_decode($token) { $len = strlen($token); if (!$len) return $token; $digit = $token[$len-1]; if (!in_array($digit, range(0,2))) { throw InvalidArgumentException(sprintf('Invalid end digit (%s).', $digit)); } return base64_decode(substr($token, 0, -1)); }
hakre Sep 16 '11 at 18:12 2011-09-16 18:12
source share