Class StringDigester
java.lang.Object
net.shibboleth.utilities.java.support.codec.StringDigester
A function which accepts a String input, digests it according to a specified
MessageDigest algorithm,
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 ClassesModifier and TypeClassDescriptionstatic enumThe output format determining how the the digested byte[] is converted to the output String. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final CharsetThe default input character set.private StringThe message digest algorithm to use.private CharsetThe Charset instance used in converting the input String to a byte[].private final org.slf4j.LoggerLogger.private StringDigester.OutputFormatThe output format instance used to determine how the digested byte[] is converted to the output String.private booleanWhether to require a salt to return any output.private StringOptional salt to add into the digest. -
Constructor Summary
ConstructorsConstructorDescriptionStringDigester(String algorithm, StringDigester.OutputFormat format) Constructor.StringDigester(String algorithm, StringDigester.OutputFormat format, Charset charset) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionprivate StringencodeOutput(byte[] digestedBytes) Apply the output encoding.voidsetRequireSalt(boolean flag) Set whether to return any data if no salt is set.voidSet a salt to add to the digest input for obfuscation.
-
Field Details
-
DEFAULT_INPUT_CHARSET
The default input character set. -
log
@Nonnull private final org.slf4j.Logger logLogger. -
digestAlgorithm
The message digest algorithm to use. -
outputFormat
The output format instance used to determine how the digested byte[] is converted to the output String. -
inputCharset
The Charset instance used in converting the input String to a byte[]. -
salt
Optional salt to add into the digest. -
requireSalt
private boolean requireSaltWhether to require a salt to return any output.
-
-
Constructor Details
-
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 Details
-
setSalt
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
-
apply
-
encodeOutput
Apply the output encoding.- Parameters:
digestedBytes- input to encoding- Returns:
- encoded string or null if the format is unknown
-