Class StringDigester

All Implemented Interfaces:

public class StringDigester extends Object implements Function<String,String>
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.
  • Field Details


      @Nonnull public static final Charset DEFAULT_INPUT_CHARSET
      The default input character set.
    • log

      @Nonnull private final org.slf4j.Logger log
    • 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 Details

  • Method Details

    • setSalt

      public void setSalt(@Nullable @NotEmpty String s)
      Set a salt to add to the digest input for obfuscation.
      s - salt value
    • setRequireSalt

      public void setRequireSalt(boolean flag)
      Set whether to return any data if no salt is set.
      flag - flag to set
    • apply

      @Nullable public String apply(@Nullable String input)
      Specified by:
      apply in interface Function<String,String>
    • encodeOutput

      @Nullable private String encodeOutput(@Nonnull byte[] digestedBytes)
      Apply the output encoding.
      digestedBytes - input to encoding
      encoded string or null if the format is unknown