Class SCryptUtil

java.lang.Object
com.lambdaworks.crypto.SCryptUtil

public class SCryptUtil extends Object
Simple SCrypt interface for hashing passwords using the scrypt key derivation function and comparing a plain text password to a hashed one. The hashed output is an extended implementation of the Modular Crypt Format that also includes the scrypt algorithm parameters. Format: $s0$PARAMS$SALT$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
s0 identifies version 0 of the scrypt format, using a 128-bit salt and 256-bit derived key.
  • Constructor Details

    • SCryptUtil

      public SCryptUtil()
  • Method Details

    • scrypt

      public static String scrypt(String passwd, int N, int r, int p)
      Hash the supplied plaintext password and generate output in the format described in SCryptUtil.
      Parameters:
      passwd - Password.
      N - CPU cost parameter.
      r - Memory cost parameter.
      p - Parallelization parameter.
      Returns:
      The hashed password.
    • check

      public static boolean check(String passwd, String hashed)
      Compare the supplied plaintext password to a hashed password.
      Parameters:
      passwd - Plaintext password.
      hashed - scrypt hashed password.
      Returns:
      true if passwd matches hashed value.
    • log2

      private static int log2(int n)