public class ConcatCombineAlgorithm extends Object implements CombineAlgorithm
Simplest implementation of combine algorithm. It combines inputs consecutively (simple concatenation).
It implies that this algorithm needs to know length of first input if split(byte[]) will be used.
combine(byte[], byte[]), there is no need to provide the length of first input, so
you can use ConcatCombineAlgorithm() constructor.combine(byte[], byte[]) and split(byte[]), you must provide expected
length of first input, so you should use ConcatCombineAlgorithm(int) constructor.
Note that this class is immutable so when this first input length is once set, then all first inputs needs to have
this length, otherwise IllegalArgumentException may occur.
This algorithm is sufficient for most cases. It is not a problem for (input + salt) usage before hashing because only combine is used (split is not needed). Also it is not a problem for (IV + cipher text) during CBC because first input (IV) has always fixed length equal to cipher block size.
On the other hand, if you need split(byte[]) and expect dynamic size of both inputs, you must create new instance
every time you want to combine and split.
SaltingAdapter,
SymmetricAlgorithm| Constructor and Description |
|---|
ConcatCombineAlgorithm()
Creates a new instance of combine algorithm.
|
ConcatCombineAlgorithm(int input1Length)
Creates a new instance of combine algorithm.
|
| Modifier and Type | Method and Description |
|---|---|
byte[] |
combine(byte[] input1,
byte[] input2)
Combines together two byte arrays.
|
byte[][] |
split(byte[] combined)
Splits input (that was combined earlier) back to original.
|
public ConcatCombineAlgorithm()
combine(byte[], byte[]) inputs but not
split(byte[]).public ConcatCombineAlgorithm(int input1Length)
combine(byte[], byte[]) and split(byte[]).
You as a client are responsible to provide first inputinput1Length - expected length of first inputspublic byte[] combine(byte[] input1,
byte[] input2)
CombineAlgorithmcombine in interface CombineAlgorithminput1 - first input to be combinedinput2 - second input to be combinedpublic byte[][] split(byte[] combined)
CombineAlgorithmsplit in interface CombineAlgorithmcombined - previously combined inputCopyright © 2014. All rights reserved.