Package org.cryptacular
Class SaltedHash
java.lang.Object
org.cryptacular.SaltedHash
Container for the output of a salted hash operation that includes both the digest output and salt value.
- Author:
- Middleware Services
-
Constructor Summary
ConstructorsConstructorDescriptionSaltedHash
(byte[] hash, byte[] salt) Creates a new instance with digest and salt data.SaltedHash
(byte[] hashWithSalt, int digestLength, boolean toEnd) Creates a new instance from byte input that contains the concatenation of digest output and salt. -
Method Summary
Modifier and TypeMethodDescriptionbyte[]
concatenateSalt
(boolean toEnd) Gets a byte array containing the concatenation of digest output and salt.concatenateSalt
(boolean toEnd, Encoder encoder) Gets an encoded string of the concatenation of digest output and salt.byte[]
getHash()
byte[]
getSalt()
byte[]
getSalt
(int n) Gets N bytes of salt.
-
Constructor Details
-
SaltedHash
public SaltedHash(byte[] hash, byte[] salt) Creates a new instance with digest and salt data.- Parameters:
hash
- Digest output.salt
- Salt value used to compute salt.
-
SaltedHash
public SaltedHash(byte[] hashWithSalt, int digestLength, boolean toEnd) Creates a new instance from byte input that contains the concatenation of digest output and salt.- Parameters:
hashWithSalt
- Concatenation of hash and salt.digestLength
- Number of bytes in digest output.toEnd
- True if salt is appended to end of hash, false if salt is prepended to hash.
-
-
Method Details
-
getHash
public byte[] getHash()- Returns:
- Digest output.
-
getSalt
public byte[] getSalt()- Returns:
- Salt value.
-
getSalt
public byte[] getSalt(int n) Gets N bytes of salt.- Parameters:
n
- Number of bytes of salt; must be less than or equal to salt size.- Returns:
- First N bytes of salt.
-
concatenateSalt
Gets an encoded string of the concatenation of digest output and salt.- Parameters:
toEnd
- True to append salt to end of hash, false to prefix hash with salt.encoder
- Encodes concatenated bytes to a string.- Returns:
- Salt concatenated to hash encoded as a string.
-
concatenateSalt
public byte[] concatenateSalt(boolean toEnd) Gets a byte array containing the concatenation of digest output and salt.- Parameters:
toEnd
- True to append salt to end of hash, false to prefix hash with salt.- Returns:
- Salt concatenated to hash.
-