You can not have something represented in base64 with just this range of characters (AZ, az and 0-9) because this range has only 62 characters and base64 requires 64 different representations .
p>
So if you do not want the + and / characters in your base64 representation, you need to replace them with something else outside this range. You'll have to choose a replacement for = also because it may appear in a base64 representation to complete the last block size.
What has been used in practice, when it is necessary for example to include a base64 representation in a URL, is to replace the set + / = } by { - _ ,
In a quick search, it seemed to me that PHP does not natively have a function for this, so you'll have to implement your own.
Even if you do not intend to use it in URL, this idea should serve:
function base64url_encode($plainText) {
$base64 = base64_encode($plainText);
$base64url = strtr($base64, '+/=', '-_,');
return $base64url;
}
function base64url_decode($plainText) {
$base64url = strtr($plainText, '-_,', '+/=');
$base64 = base64_decode($base64url);
return $base64;
}
Update: It just occurred to me that you can convert your bytes to Hexadecimal , which is represented only by 0-9 and A-F. The resulting string is much larger than the base64 representation, but it might serve you. I do not know PHP function that does this but the logic of converting bytes to hexadecimal is quite simple.