Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

possible characters base64 url safe function

Tags:

php

base64

What is the range of possible characters returned from this string?

function base64url_encode($data)  {    return rtrim(strtr(base64_encode($data), '+/', '-_'), '=');  }  

My guess is [a-z0-9-_]

like image 239
Chris Muench Avatar asked May 23 '11 19:05

Chris Muench


People also ask

What characters are allowed in Base64?

Base64 only contains A–Z , a–z , 0–9 , + , / and = . So the list of characters not to be used is: all possible characters minus the ones mentioned above. For special purposes .

What is URL safe Base64 encoding?

Base64 is a group of binary-to-text encoding schemes that represent binary data in an ASCII string format by translating it into a radix-64 representation. By consisting only of ASCII characters, base64 strings are generally url-safe, and that's why they can be used to encode data in Data URLs.

What characters are not allowed in Base64?

The base 64 digits in ascending order from zero are the uppercase characters 'A' to 'Z', lowercase characters 'a' to 'z', numerals '0' to '9', and the symbols '+' and '/'. % is not allowed in base64 encoding.


2 Answers

Base64 encoded strings may contain the characters a-z A-Z 0-9 + / =.

You're removing the right-padding = and replacing + with - and / with _.

So in your case, the possible characters are a-z A-Z 0-9 - _

More Info

like image 198
Floern Avatar answered Sep 21 '22 07:09

Floern


The range of possible characters returned are:

  • A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z
  • a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z
  • 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
  • - (minus) and _ (underscore)

In your regex-style, that would be [a-zA-Z0-9_-].

like image 33
salathe Avatar answered Sep 19 '22 07:09

salathe