php 可能的字符 base64 url​​ 安全功能

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6102077/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 23:21:39  来源:igfitidea点击:

possible characters base64 url safe function

phpbase64

提问by Chris Muench

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-_]

我的猜测是 [a-z0-9-_]

回答by Floern

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

Base64 编码的字符串可能包含字符a-z A-Z 0-9 + / =

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

您要移除右填充=和更换+-/_

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

所以在你的情况下,是的,可能的字符是 a-z A-Z 0-9 - _

More Info

更多信息

回答by salathe

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)
  • 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
  • -减号)和_下划线

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

在您的正则表达式风格中,这将是[a-zA-Z0-9_-].