* @param lengthBytes length in bytes.
* @return the generated salt.
*/
public byte[] generateSalt(int lengthBytes) {
if (this.salt == null) {
throw new EncryptionInitializationException(
"Salt has not been set");
}
if (this.saltBytes == null) {
try {
this.saltBytes = this.salt.getBytes(this.charset);
} catch (UnsupportedEncodingException e) {
throw new EncryptionInitializationException(
"Invalid charset specified: " + this.charset);
}
}
if (this.saltBytes.length < lengthBytes) {
throw new EncryptionInitializationException(
"Requested salt larger than set");
}
return ArrayUtils.subarray(this.saltBytes, 0, lengthBytes);
}