Package com.lambdaworks.crypto
Class SCryptUtil
- java.lang.Object
-
- com.lambdaworks.crypto.SCryptUtil
-
public class SCryptUtil extends java.lang.ObjectSimpleSCryptinterface 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
s0identifies 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 booleancheck(java.lang.String passwd, java.lang.String hashed)Compare the supplied plaintext password to a hashed password.private static intlog2(int n)static java.lang.Stringscrypt(java.lang.String passwd, int N, int r, int p)Hash the supplied plaintext password and generate output in the format described inSCryptUtil.
-
-
-
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 inSCryptUtil.- 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)
-
-