android 签名哈希 AADB2C android 平台的 base64 编码 SHA1 的正则表达式

Regex for base64-encoded SHA1 for android signature hash AADB2C android platform

我需要 android 签名哈希的正则表达式,它在图片中显示的字段中以 azure 形式使用。

我用过类似的东西:

"^(?=.{28}$)(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$"

它匹配 base64 编码的 28 个字符的单词,但它也会匹配例如platformAndroidSignatureHash 天蓝色下降(显示在图片上)。

工作示例:

熟悉base64 encoding, especially read about padding, but in short: your "faked" String should probably ends with = or ==. you can't use regexp in here, as you should do some bitwise math, as every base64 digit needs 6 bits, in the meanwhile common usage (e.g. printing on screen) would use 8 bits per digit. you have to calculate/respect this padding. more info in THIS主题(阅读所有答案和评论,接受的不可靠!)

它匹配platformAndroidSignatureHash,因为最后一个等号部分是可选的。

您可以将模式重写为

^(?=.{28}$)(?:[A-Za-z0-9+/]{4})+[A-Za-z0-9+/]{2,3}==?$

模式匹配;

  • ^ 字符串开头
  • (?=.{28}$) 正面前瞻,断言 28 个字符
  • (?:[A-Za-z0-9+/]{4})+ 重复字符中列出的 4 个字符 1+ 次 class
  • [A-Za-z0-9+/]{2,3} 匹配列出的字符之一重复 2-3 次
  • ==? 匹配 ===
  • $ 字符串结束

Regex demo