Question

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
Was it helpful?

Solution

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/+]+[=]*$
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top