public final class SaltingAdapter extends Object implements SaltedHashingAlgorithm
Adapter for hashing algorithms that combines input text and salt before it is processed by adapted algorithm.
For combination, you can implement your own Combining or you can use default one.
HashingAlgorithm sha256 = new SHA256();
SaltingAdapter adapter = new SaltingAdapter(alg); // ConcatCombineAlgorithm
adapter.hash("your input text", "your salt");
// or with custom combine algorithm
Combining combineAlg = ...; // your implementation
SaltingAdapter adapter = new SaltingAdapter(alg, combineAlg); // ConcatCombineAlgorithm
Be sure to store the salt along with the hash for future checks.
ConcatAlgorithm| Modifier | Constructor and Description |
|---|---|
protected |
SaltingAdapter(HashingAlgorithm hashingAlgorithm,
BytesRepresentation bytesRepresentation,
Combining inputSaltCombining,
String encoding)
Creates a new salting adapter.
|
| Modifier and Type | Method and Description |
|---|---|
byte[] |
hash(byte[] input,
byte[] salt)
Creates a hash from given input bytes and given salt bytes.
|
String |
hash(String input,
String salt)
Creates a hash from given input and given salt.
|
protected SaltingAdapter(HashingAlgorithm hashingAlgorithm, BytesRepresentation bytesRepresentation, Combining inputSaltCombining, String encoding)
hashingAlgorithm - algorithm for hashingbytesRepresentation - representation of bytesinputSaltCombining - strategy how to combine input text and saltencoding - encoding for used stringspublic String hash(String input, String salt) throws HashingException
SaltedHashingAlgorithmhash in interface SaltedHashingAlgorithminput - input to be hashedsalt - salt to be added to inputHashingException - possible exception during hashingpublic byte[] hash(byte[] input,
byte[] salt)
throws HashingException
SaltedHashingAlgorithmhash in interface SaltedHashingAlgorithminput - input to be hashedsalt - salt to be added to inputHashingException - possible exception during hashing processCopyright © 2019. All rights reserved.