@Scriptable public final class KeyedSaltedHashing extends Object
This class implements a HMAC keyed and SALTed hashing algorithm. It is closely related to the mechanism described in RFC 2104, HMAC: Keyed-Hashing for Message Authentication. Beyond that, it supports SALT in a way that is compatible with common password storing strategies
Constructor and Description |
---|
KeyedSaltedHashing()
Contruct the hashing class with SHA-1 as the undelying hashing algorithm.
|
KeyedSaltedHashing(String p_strAlgorithm)
Contruct the hashing class with the specified hashing algorithm.
|
Modifier and Type | Method and Description |
---|---|
boolean |
equals(KeyedSaltedHashing p_another)
Deprecated.
Do not use this method.
|
byte[] |
getDigest()
Get the digest.
|
byte[] |
makeDigest(byte[] p_hashedPassword,
byte[] p_message)
Create the HMAC.
|
byte[] |
makeDigest(byte[] p_password,
byte[] p_salt,
byte[] p_message)
Create the HMAC.
|
static boolean |
verify(byte[] p_response,
byte[] p_hashedPassword,
byte[] p_challenge)
Verify a given client login response using SHA-1 as the hashing algorithm.
|
static boolean |
verify(byte[] p_response,
byte[] p_hashedPassword,
byte[] p_challenge,
String p_strAlgorithm)
Verify a given client login response.
|
public KeyedSaltedHashing()
public KeyedSaltedHashing(String p_strAlgorithm) throws NoSuchAlgorithmException
NoSuchAlgorithmException
- If the algorithm is not available in the
caller's environment.public static boolean verify(byte[] p_response, byte[] p_hashedPassword, byte[] p_challenge)
This method calls
to calculate
the expected response, and then securely compares it with the response given by the
client.makeDigest(byte[], byte[])
p_response
- The client response.p_hashedPassword
- The hashed password.p_challenge
- The challenge.true
if the client's response is correct, or false
otherwise.public static boolean verify(byte[] p_response, byte[] p_hashedPassword, byte[] p_challenge, String p_strAlgorithm) throws NoSuchAlgorithmException
This method calls
to calculate
the expected response, and then securely compares it with the response given by the
client.makeDigest(byte[], byte[])
p_response
- The client response.p_hashedPassword
- The hashed password.p_challenge
- The challenge.p_strAlgorithm
- The hashing algorithm to be used.true
if the client's response is correct, or false
otherwise.NoSuchAlgorithmException
- If the requested hashing algorithm is not available.@Deprecated public boolean equals(KeyedSaltedHashing p_another)
KeyedSaltedHashing
p_another
- Another instance of KeyedSaltedHashing
to compare with.true
if the two underlying digests are the same or both digest
are null
, false
otherwise.public byte[] makeDigest(byte[] p_password, byte[] p_salt, byte[] p_message) throws NullPointerException
The HMAC is computed from the password, the SALT and the message
p_password
- The plain password as a byte
array.p_salt
- The SALT as a byte
array or
null
if SALT should not be used.p_message
- The message (e.g. challenge) as a byte
array.NullPointerException
- if the password or
the message is null
public byte[] makeDigest(byte[] p_hashedPassword, byte[] p_message) throws NullPointerException
The HMAC is computed from a hashed password-SALT pair and the message
p_hashedPassword
- The hashed and password-SALT-pair as a byte
array.p_message
- The message (e.g. challenge) as a byte
array.NullPointerException
- if p_hashedPassword
or
the message is null
public byte[] getDigest()
null
if none is available.