Class StringDigester
- java.lang.Object
-
- net.shibboleth.utilities.java.support.codec.StringDigester
-
public class StringDigester extends Object implements Function<String,String>
A function which accepts a String input, digests it according to a specifiedMessageDigestalgorithm, and then returns the output in a specified format: Base32/64-encoded or hexadecimal with with lower or upper case characters.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classStringDigester.OutputFormatThe output format determining how the the digested byte[] is converted to the output String.
-
Field Summary
Fields Modifier and Type Field Description static CharsetDEFAULT_INPUT_CHARSETThe default input character set.private StringdigestAlgorithmThe message digest algorithm to use.private CharsetinputCharsetThe Charset instance used in converting the input String to a byte[].private org.slf4j.LoggerlogLogger.private StringDigester.OutputFormatoutputFormatThe output format instance used to determine how the digested byte[] is converted to the output String.private booleanrequireSaltWhether to require a salt to return any output.private StringsaltOptional salt to add into the digest.
-
Constructor Summary
Constructors Constructor Description StringDigester(String algorithm, StringDigester.OutputFormat format)Constructor.StringDigester(String algorithm, StringDigester.OutputFormat format, Charset charset)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Stringapply(String input)private StringencodeOutput(byte[] digestedBytes)Apply the output encoding.voidsetRequireSalt(boolean flag)Set whether to return any data if no salt is set.voidsetSalt(String s)Set a salt to add to the digest input for obfuscation.
-
-
-
Field Detail
-
DEFAULT_INPUT_CHARSET
@Nonnull public static final Charset DEFAULT_INPUT_CHARSET
The default input character set.
-
log
@Nonnull private final org.slf4j.Logger log
Logger.
-
digestAlgorithm
@Nonnull @NotEmpty private String digestAlgorithm
The message digest algorithm to use.
-
outputFormat
@Nonnull private StringDigester.OutputFormat outputFormat
The output format instance used to determine how the digested byte[] is converted to the output String.
-
inputCharset
@Nonnull private Charset inputCharset
The Charset instance used in converting the input String to a byte[].
-
salt
@Nullable private String salt
Optional salt to add into the digest.
-
requireSalt
private boolean requireSalt
Whether to require a salt to return any output.
-
-
Constructor Detail
-
StringDigester
public StringDigester(@Nonnull @NotEmpty @ParameterName(name="algorithm") String algorithm, @Nonnull @ParameterName(name="format") StringDigester.OutputFormat format) throws NoSuchAlgorithmException
Constructor.The input character set will be UTF-8.
- Parameters:
algorithm- the JCA digest algorithm identifierformat- the output format used to convert the digested[] to the output string- Throws:
NoSuchAlgorithmException- thrown if the digestAlgorithm is not invalid or unsupported
-
StringDigester
public StringDigester(@Nonnull @NotEmpty @ParameterName(name="algorithm") String algorithm, @Nonnull @ParameterName(name="format") StringDigester.OutputFormat format, @Nullable @ParameterName(name="charset") Charset charset) throws NoSuchAlgorithmException
Constructor.- Parameters:
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 digesting- Throws:
NoSuchAlgorithmException- thrown if the digestAlgorithm is not invalid or unsupported
-
-
Method Detail
-
setSalt
public void setSalt(@Nullable @NotEmpty String s)
Set a salt to add to the digest input for obfuscation.- Parameters:
s- salt value
-
setRequireSalt
public void setRequireSalt(boolean flag)
Set whether to return any data if no salt is set.- Parameters:
flag- flag to set
-
encodeOutput
@Nullable private String encodeOutput(@Nonnull byte[] digestedBytes)
Apply the output encoding.- Parameters:
digestedBytes- input to encoding- Returns:
- encoded string or null if the format is unknown
-
-