Package com.lambdaworks.crypto
Class SCryptUtil
java.lang.Object
com.lambdaworks.crypto.SCryptUtil
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 -
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
Compare the supplied plaintext password to a hashed password.private static int
log2
(int n) static String
Hash the supplied plaintext password and generate output in the format described inSCryptUtil
.
-
Constructor Details
-
SCryptUtil
public SCryptUtil()
-
-
Method Details
-
scrypt
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
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)
-