public class StringDigester
extends java.lang.Object
implements com.google.common.base.Function<java.lang.String,java.lang.String>
MessageDigest algorithm,
and then returns the output in a specified format: Base64-encoded or hexadecimal with with lower or upper
case characters.| Modifier and Type | Class and Description |
|---|---|
static class |
StringDigester.OutputFormat
The output format determining how the the digested byte[] is converted to the output String.
|
| Modifier and Type | Field and Description |
|---|---|
static java.nio.charset.Charset |
DEFAULT_INPUT_CHARSET
The default input character set.
|
private java.lang.String |
digestAlgorithm
The message digest algorithm to use.
|
private java.nio.charset.Charset |
inputCharset
The Charset instance used in converting the input String to a byte[].
|
private org.slf4j.Logger |
log
Logger.
|
private StringDigester.OutputFormat |
outputFormat
The output format instance used to determine how the digested byte[] is converted to the output String.
|
private java.lang.String |
salt
Optional salt to add into the digest.
|
| Constructor and Description |
|---|
StringDigester(java.lang.String algorithm,
StringDigester.OutputFormat format)
Constructor.
|
StringDigester(java.lang.String algorithm,
StringDigester.OutputFormat format,
java.nio.charset.Charset charset)
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
java.lang.String |
apply(java.lang.String input) |
void |
setSalt(java.lang.String s)
Set a salt to add to the digest input for obfuscation.
|
@Nonnull public static final java.nio.charset.Charset DEFAULT_INPUT_CHARSET
@Nonnull private final org.slf4j.Logger log
@Nonnull @NotEmpty private java.lang.String digestAlgorithm
@Nonnull private StringDigester.OutputFormat outputFormat
@Nonnull private java.nio.charset.Charset inputCharset
@Nullable private java.lang.String salt
public StringDigester(@Nonnull @NotEmpty java.lang.String algorithm, @Nonnull StringDigester.OutputFormat format) throws java.security.NoSuchAlgorithmException
The input character set will be UTF-8.
algorithm - the JCA digest algorithm identifierformat - the output format used to convert the digested[] to the output stringjava.security.NoSuchAlgorithmException - thrown if the digestAlgorithm is not invalid or unsupportedpublic StringDigester(@Nonnull @NotEmpty java.lang.String algorithm, @Nonnull StringDigester.OutputFormat format, @Nullable java.nio.charset.Charset charset) throws java.security.NoSuchAlgorithmException
algorithm - the JCA digest algorithm identifierformat - the output format used to convert the digested[] to the output stringcharset - the character set to use in converting the input string to a byte[] prior to digestingjava.security.NoSuchAlgorithmException - thrown if the digestAlgorithm is not invalid or unsupportedpublic void setSalt(@Nullable
java.lang.String s)
s - salt value@Nullable
public java.lang.String apply(@Nullable
java.lang.String input)
apply in interface com.google.common.base.Function<java.lang.String,java.lang.String>