- Basic:
Uses "The Base64 Alphabet" as specified in Table 1 of RFC 4648 for encoding and decoding operation. The encoder does not add any line feed (line separator) character. The decoder rejects data that contains characters outside the base64 alphabet.
- URL and Filename Safe:
Uses the "URL and Filename Safe Base64 Alphabet" as specified in Table 2 of RFC 4648 for encoding and decoding. The encoder does not add any line feed (line separator) character. The decoder rejects data that contains characters outside the base64 alphabet.
The Base64 padding character "=" is accepted and interpreted at the end of the encoded data, but is not required. So if the final unit of the encoded data only has two or three Base64 characters without the corresponding padding characters, they are decoded as if followed by padding characters. If there is a padding character present in the final unit, the correct number of padding characters must be present, otherwise an exception is thrown.
-
Method Summary
Modifier and TypeMethodDescriptionstatic byte[]
decode
(char[] chars, int offset, int length, boolean urlSafe) Decodes a byte array from supplied Base64 character sequence.static byte[]
decodeBasic
(char[] chars) Decodes a byte array from supplied Base64 Basic character array.static byte[]
decodeBasic
(char[] chars, int offset, int length) Decodes a byte array from supplied Base64 Basic character sequence.static byte[]
decodeBasic
(String str) Decodes a byte array from supplied Base64 Basic string.static byte[]
decodeUrlSafe
(char[] chars) Decodes a byte array from supplied Base64 URL Safe character array.static byte[]
decodeUrlSafe
(char[] chars, int offset, int length) Decodes a byte array from supplied Base64 URL Safe character sequence.static byte[]
decodeUrlSafe
(String str) Decodes a byte array from supplied Base64 URL Safe string.static String
encode
(byte[] bytes, int offset, int length, boolean urlSafe, boolean addPadding) Encodes supplied byte sequence to a Base64 representation.static String
encodeBasic
(byte[] bytes) Encodes supplied byte array to a Base64 Basic representation.static String
encodeBasic
(byte[] bytes, int offset, int length) Encodes supplied byte sequence to a Base64 Basic representation.static String
encodeUrlSafe
(byte[] bytes) Encodes supplied byte array to a Base64 URL Safe representation.static String
encodeUrlSafe
(byte[] bytes, int offset, int length) Encodes supplied byte sequence to a Base64 URL Safe representation.
-
Method Details
-
encodeBasic
Encodes supplied byte array to a Base64 Basic representation.- Parameters:
bytes
- the byte array to encode.- Returns:
- the Base64 Basic representation of supplied bytes.
- Throws:
NullPointerException
- ifbytes
isnull
.
-
encodeBasic
Encodes supplied byte sequence to a Base64 Basic representation.- Parameters:
bytes
- the byte array to encode.offset
- the index of first byte to encode.length
- the number of bytes to encode.- Returns:
- the Base64 Basic representation of specified bytes.
- Throws:
NullPointerException
- ifbytes
isnull
.IndexOutOfBoundsException
- if an argument is out-of-bounds.
-
encodeUrlSafe
Encodes supplied byte array to a Base64 URL Safe representation.- Parameters:
bytes
- the byte array to encode.- Returns:
- the Base64 URL Safe representation of supplied bytes.
- Throws:
NullPointerException
- ifbytes
isnull
.
-
encodeUrlSafe
Encodes supplied byte sequence to a Base64 URL Safe representation.- Parameters:
bytes
- the byte array to encode.offset
- the index of first byte to encode.length
- the number of bytes to encode.- Returns:
- the Base64 URL Safe representation of specified bytes.
- Throws:
NullPointerException
- ifbytes
isnull
.IndexOutOfBoundsException
- if an argument is out-of-bounds.
-
encode
public static String encode(byte[] bytes, int offset, int length, boolean urlSafe, boolean addPadding) Encodes supplied byte sequence to a Base64 representation.- Parameters:
bytes
- the byte array to encode.offset
- the index of first byte to encode.length
- the number of bytes to encode.urlSafe
- iftrue
use Base64 URL Safe encoding.addPadding
- iftrue
add "=" padding characters.- Returns:
- the Base64 representation of specified byte sequence.
- Throws:
NullPointerException
- ifbytes
isnull
.IllegalArgumentException
- if an argument is invalid.IndexOutOfBoundsException
- if an argument is out-of-bounds.
-
decodeBasic
Decodes a byte array from supplied Base64 Basic string.- Parameters:
str
- the string to decode.- Returns:
- the byte array decoded from supplied string.
- Throws:
NullPointerException
- ifstr
isnull
.IllegalArgumentException
- ifstr
is invalid.
-
decodeBasic
public static byte[] decodeBasic(char[] chars) Decodes a byte array from supplied Base64 Basic character array.- Parameters:
chars
- the character array to decode.- Returns:
- the byte array decoded from supplied characters.
- Throws:
NullPointerException
- ifchars
isnull
.IllegalArgumentException
- ifchars
is invalid.
-
decodeBasic
public static byte[] decodeBasic(char[] chars, int offset, int length) Decodes a byte array from supplied Base64 Basic character sequence.- Parameters:
chars
- the character array to decode.offset
- the index of first character to decode.length
- the number of characters to decode.- Returns:
- the byte array decoded from specified characters.
- Throws:
NullPointerException
- ifchars
isnull
.IllegalArgumentException
- if an argument is invalid.IndexOutOfBoundsException
- if an argument is out-of-bounds.
-
decodeUrlSafe
Decodes a byte array from supplied Base64 URL Safe string.- Parameters:
str
- the string to decode.- Returns:
- the byte array decoded from supplied string.
- Throws:
NullPointerException
- ifstr
isnull
.IllegalArgumentException
- ifstr
is invalid.
-
decodeUrlSafe
public static byte[] decodeUrlSafe(char[] chars) Decodes a byte array from supplied Base64 URL Safe character array.- Parameters:
chars
- the character array to decode.- Returns:
- the byte array decoded from supplied characters.
- Throws:
NullPointerException
- ifchars
isnull
.IllegalArgumentException
- ifchars
is invalid.
-
decodeUrlSafe
public static byte[] decodeUrlSafe(char[] chars, int offset, int length) Decodes a byte array from supplied Base64 URL Safe character sequence.- Parameters:
chars
- the character array to decode.offset
- the index of first character to decode.length
- the number of characters to decode.- Returns:
- the byte array decoded from specified characters.
- Throws:
NullPointerException
- ifchars
isnull
.IllegalArgumentException
- if an argument is invalid.IndexOutOfBoundsException
- if an argument is out-of-bounds.
-
decode
public static byte[] decode(char[] chars, int offset, int length, boolean urlSafe) Decodes a byte array from supplied Base64 character sequence.- Parameters:
chars
- the character array to decode.offset
- the index of first character to decode.length
- the number of characters to decode.urlSafe
- iftrue
use Base64 URL Safe decoding.- Returns:
- the byte array decoded from specified character sequence.
- Throws:
NullPointerException
- ifchars
isnull
.IllegalArgumentException
- if an argument is invalid.IndexOutOfBoundsException
- if an argument is out-of-bounds.
-