public class SaltingAdapter extends Object
Adapter for hashing algorithms that combines input text and salt before it is processed by adapted algorithm.
For combination, you can implement your own CombineAlgorithm 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
CombineAlgorithm combineAlg = ...; // your implementation
SaltingAdapter adapter = new SaltingAdapter(alg, combineAlg); // ConcatCombineAlgorithm
Be sure to store the salt along with the hash for future checks.
ConcatCombineAlgorithm| Modifier | Constructor and Description |
|---|---|
protected |
SaltingAdapter(HashingAlgorithm hashingAlgorithm,
CombineAlgorithm combineAlgorithm,
String encoding)
Creates a new salting adapter.
|
| Modifier and Type | Method and Description |
|---|---|
byte[] |
hash(byte[] input,
byte[] salt)
Hashes given input with given salt using adapted hashing algorithm.
|
String |
hash(String input,
String salt)
Hashes given input with given salt using adapted hashing algorithm.
|
protected SaltingAdapter(HashingAlgorithm hashingAlgorithm, CombineAlgorithm combineAlgorithm, String encoding)
hashingAlgorithm - algorithm for hashingcombineAlgorithm - strategy how to combine input text and saltencoding - encoding for used stringspublic String hash(String input, String salt) throws HashingException
input - input to be hashedsalt - salt to be added to inputHashingException - possible exception during hashingpublic byte[] hash(byte[] input,
byte[] salt)
throws HashingException
input - input to be hashedsalt - salt to be added to inputHashingException - possible exception during hashingCopyright © 2014. All rights reserved.