public class SCryptPasswordEncoder extends Object implements PasswordEncoder
Implementation of PasswordEncoder that uses the SCrypt hashing function. Clients can optionally supply a cpu cost parameter, a memory cost parameter and a parallelization parameter.
A few warnings:
Constructor and Description |
---|
SCryptPasswordEncoder() |
SCryptPasswordEncoder(int cpuCost,
int memoryCost,
int parallelization,
int keyLength,
int saltLength)
Creates a new instance
|
Modifier and Type | Method and Description |
---|---|
String |
encode(CharSequence rawPassword)
Encode the raw password.
|
boolean |
matches(CharSequence rawPassword,
String encodedPassword)
Verify the encoded password obtained from storage matches the submitted raw
password after it too is encoded.
|
public SCryptPasswordEncoder()
public SCryptPasswordEncoder(int cpuCost, int memoryCost, int parallelization, int keyLength, int saltLength)
cpuCost
- cpu cost of the algorithm (as defined in scrypt this is N).
must be power of 2 greater than 1. Default is currently 16,348
or 2^14)memoryCost
- memory cost of the algorithm (as defined in scrypt this is r)
Default is currently 8.parallelization
- the parallelization of the algorithm (as defined in scrypt
this is p) Default is currently 1. Note that the
implementation does not currently take advantage of
parallelization.keyLength
- key length for the algorithm (as defined in scrypt this is
dkLen). The default is currently 32.saltLength
- salt length (as defined in scrypt this is the length of S).
The default is currently 64.public String encode(CharSequence rawPassword)
PasswordEncoder
encode
in interface PasswordEncoder
public boolean matches(CharSequence rawPassword, String encodedPassword)
PasswordEncoder
matches
in interface PasswordEncoder
rawPassword
- the raw password to encode and matchencodedPassword
- the encoded password from storage to compare with