Package net.shibboleth.shared.codec

# Class StringDigester

java.lang.Object
net.shibboleth.shared.codec.StringDigester

All Implemented Interfaces:
  `Function<String,String>`

Direct Known Subclasses:
  `StringDigester`

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.

## Nested Class Summary

Nested Classes
Modifier and Type
Class
Description
`static enum`
`StringDigester.OutputFormat`
The output format determining how the the digested byte[] is converted to the output String.

## Field Summary

Fields
Modifier and Type
Field
Description
`static final Charset`
`DEFAULT_INPUT_CHARSET`
The default input character set.
`private String`
`digestAlgorithm`
The message digest algorithm to use.
`private Charset`
`inputCharset`
The Charset instance used in converting the input String to a byte[].
`private final 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 boolean`
`requireSalt`
Whether to require a salt to return any output.
`private String`
`salt`
Optional 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

Modifier and Type
Method
Description
`String`
`apply(String input)`
`private String`
`encodeOutput(byte[] digestedBytes)`
Apply the output encoding.
`void`
`setRequireSalt(boolean flag)`
Set whether to return any data if no salt is set.
`void`
`setSalt(String s)`
Set a salt to add to the digest input for obfuscation.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Methods inherited from interface java.util.function.Function

`andThen, compose`

## Field Details

### 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 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 identifier
  `format` - 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 identifier
  `format` - the output format used to convert the digested[] to the output string
  `charset` - 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

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

### 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.

Parameters:
  `digestedBytes` - input to encoding
Returns:
  encoded string or null if the format is unknown