简体   繁体   中英

Regular Expression to match scrypt

I need to probe if a given String matches a scrypt key.

Some examples that need to match:

$s0$e0801$epIxT/h6HbbwHaehFnh/bw==$7H0vsXlY8UxxyW/BWx/9GuY7jEvGjT71GFd6O4SZND0=
$s0$100808$6McCjsQBpcCShLWq4nl3gg==$gs+Tz5DLGCDtYHGpIkP4i3EDpufBzsEGvoXzegkO5cU=

I use Javas String.matches function.

The description of the Keys is like this: Basic form: $s0$params$salt$key The values stand for:

  • s0 - version 0 of the format with 128-bit salt and 256-bit derived key
  • params - 32-bit hex integer containing log2(N) (16 bits), r (8 bits), and p (8 bits)
  • salt - base64-encoded salt
  • key - base64-encoded derived key

This is the best I could come up with. Any better answer is greatly appreciated.

Java:
String match = "^\\$s0\\$[0-9a-f]{5,6}\\$[a-zA-Z0-9/+]+[=]*\\$[a-zA-Z0-9/+]+[=]*$"

General:
^\$s0\$[0-9a-f]{5,6}\$[a-zA-Z0-9/+]+[=]*\$[a-zA-Z0-9/+]+[=]*$

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM