public class StringFixedSaltGenerator extends java.lang.Object implements FixedSaltGenerator
String based implementation of FixedSaltGenerator, that will
always return the same salt. This salt is returned as bytes using the
specified charset for conversion (UTF-8 by default).
If the requested salt has a size in bytes smaller than the specified salt, the first n bytes are returned. If it is larger, an exception is thrown.
This class is thread-safe.
| Modifier and Type | Field and Description |
|---|---|
private java.lang.String |
charset |
private static java.lang.String |
DEFAULT_CHARSET |
private java.lang.String |
salt |
private byte[] |
saltBytes |
| Constructor and Description |
|---|
StringFixedSaltGenerator(java.lang.String salt)
Creates a new instance of FixedStringSaltGenerator using
the default charset.
|
StringFixedSaltGenerator(java.lang.String salt,
java.lang.String charset)
Creates a new instance of FixedStringSaltGenerator
|
| Modifier and Type | Method and Description |
|---|---|
byte[] |
generateSalt(int lengthBytes)
Return salt with the specified byte length.
|
boolean |
includePlainSaltInEncryptionResults()
As this salt generator provides a fixed salt, its inclusion
unencrypted in encryption results
is not necessary, and in fact not desirable (so that it remains hidden).
|
private static final java.lang.String DEFAULT_CHARSET
private final java.lang.String salt
private final java.lang.String charset
private final byte[] saltBytes
public StringFixedSaltGenerator(java.lang.String salt)
salt - the specified salt.public StringFixedSaltGenerator(java.lang.String salt,
java.lang.String charset)
salt - the specified salt.charset - the specified charsetpublic byte[] generateSalt(int lengthBytes)
generateSalt in interface SaltGeneratorlengthBytes - length in bytes.public boolean includePlainSaltInEncryptionResults()
includePlainSaltInEncryptionResults in interface SaltGenerator