Class SCryptUtil


  • public class SCryptUtil
    extends java.lang.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 Summary

      Constructors 
      Constructor Description
      SCryptUtil()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static boolean check​(java.lang.String passwd, java.lang.String hashed)
      Compare the supplied plaintext password to a hashed password.
      private static int log2​(int n)  
      static java.lang.String scrypt​(java.lang.String passwd, int N, int r, int p)
      Hash the supplied plaintext password and generate output in the format described in SCryptUtil.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • SCryptUtil

        public SCryptUtil()
    • Method Detail

      • scrypt

        public static java.lang.String scrypt​(java.lang.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​(java.lang.String passwd,
                                    java.lang.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)