Class Base64Support
- java.lang.Object
-
- net.shibboleth.utilities.java.support.codec.Base64Support
-
public final class Base64Support extends Object
Helper class for working withBase64.This helper class specifically addresses that waste of the Apache Codec encode/decode static methods creating new instances of the
Base64for every operation. It also provides the helper method to produce both chunked and unchunked encoded content as strings.
-
-
Field Summary
Fields Modifier and Type Field Description static booleanCHUNKEDChunk the encoded data into 76-character lines broken by CRLF characters.private static org.apache.commons.codec.binary.Base64CHUNKED_ENCODEREncoder used to produce chunked output.static booleanUNCHUNKEDDo not chunk encoded data.private static org.apache.commons.codec.binary.Base64UNCHUNKED_ENCODEREncoder used to produce unchunked output.
-
Constructor Summary
Constructors Modifier Constructor Description privateBase64Support()Constructor.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static byte[]decode(String data)Decodes (un)chunked Base64 encoded data.static byte[]decodeURLSafe(String data)Decodes (un)chunked Base64URL encoded data.static Stringencode(byte[] data, boolean chunked)Base64 encodes the given binary data.static StringencodeURLSafe(byte[] data)Base64URL encodes the given binary data.
-
-
-
Field Detail
-
CHUNKED
public static final boolean CHUNKED
Chunk the encoded data into 76-character lines broken by CRLF characters.- See Also:
- Constant Field Values
-
UNCHUNKED
public static final boolean UNCHUNKED
Do not chunk encoded data.- See Also:
- Constant Field Values
-
CHUNKED_ENCODER
@Nonnull private static final org.apache.commons.codec.binary.Base64 CHUNKED_ENCODER
Encoder used to produce chunked output.
-
UNCHUNKED_ENCODER
@Nonnull private static final org.apache.commons.codec.binary.Base64 UNCHUNKED_ENCODER
Encoder used to produce unchunked output.
-
-
Method Detail
-
encode
@Nonnull public static String encode(@Nonnull byte[] data, boolean chunked) throws EncodingException
Base64 encodes the given binary data.- Parameters:
data- data to encodechunked- whether the encoded data should be chunked or not- Returns:
- the base64 encoded data
- Throws:
EncodingException- when anyExceptionis thrown from the underlying encoder, or the output is null.
-
decode
@Nonnull public static byte[] decode(@Nonnull String data) throws DecodingExceptionDecodes (un)chunked Base64 encoded data.- Parameters:
data- Base64 encoded data- Returns:
- the decoded data
- Throws:
DecodingException- when anyExceptionis thrown from the underlying decoder, or the output is null.
-
encodeURLSafe
@Nonnull public static String encodeURLSafe(@Nonnull byte[] data) throws EncodingException
Base64URL encodes the given binary data.This is compliant with RFC 4648, Section 5: "Base 64 Encoding with URL and Filename Safe Alphabet".
- Parameters:
data- data to encode- Returns:
- the base64url encoded data
- Throws:
EncodingException- if the input data can not be encoded as a base64 string.
-
decodeURLSafe
@Nonnull public static byte[] decodeURLSafe(@Nonnull String data) throws DecodingExceptionDecodes (un)chunked Base64URL encoded data.This is compliant with RFC 4648, Section 5: "Base 64 Encoding with URL and Filename Safe Alphabet".
- Parameters:
data- Base64URL encoded data- Returns:
- the decoded data
- Throws:
DecodingException- if unable to decode the input data.
-
-