public final class Base64 extends Object
Base64 encoders and decoders. This class supports the following types of Base64 as specified in RFC 4648:
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.
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.
Modifier and Type | Method and Description |
---|---|
static 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 bytes into a string using Base64 encoding scheme.
|
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 byte[] |
encodeToBytes(byte[] bytes,
int offset,
int length,
boolean urlSafe,
boolean addPadding)
Encodes supplied bytes into a byte array using Base64 encoding scheme.
|
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.
|
public static String encodeBasic(byte[] bytes)
bytes
- the byte array to encode.NullPointerException
- if bytes
is null
.public static String encodeBasic(byte[] bytes, int offset, int length)
bytes
- the byte array to encode.offset
- the index of first byte to encode.length
- the number of bytes to encode.NullPointerException
- if bytes
is null
.IndexOutOfBoundsException
- if an argument is out-of-bounds.public static String encodeUrlSafe(byte[] bytes)
bytes
- the byte array to encode.NullPointerException
- if bytes
is null
.public static String encodeUrlSafe(byte[] bytes, int offset, int length)
bytes
- the byte array to encode.offset
- the index of first byte to encode.length
- the number of bytes to encode.NullPointerException
- if bytes
is null
.IndexOutOfBoundsException
- if an argument is out-of-bounds.public static String encode(byte[] bytes, int offset, int length, boolean urlSafe, boolean addPadding)
bytes
- the byte array to encode.offset
- the index of first byte to encode.length
- the number of bytes to encode.urlSafe
- if true
use Base64 URL Safe encoding.addPadding
- if true
add "=" padding characters.NullPointerException
- if bytes
is null
.IllegalArgumentException
- if an argument is invalid.IndexOutOfBoundsException
- if an argument is out-of-bounds.public static byte[] encodeToBytes(byte[] bytes, int offset, int length, boolean urlSafe, boolean addPadding)
bytes
- the byte array to encode.offset
- the index of first byte to encode.length
- the number of bytes to encode.urlSafe
- if true
use Base64 URL Safe encoding.addPadding
- if true
add "=" padding characters.NullPointerException
- if bytes
is null
.IllegalArgumentException
- if an argument is invalid.IndexOutOfBoundsException
- if an argument is out-of-bounds.public static byte[] decodeBasic(String str)
str
- the string to decode.NullPointerException
- if str
is null
.IllegalArgumentException
- if str
is invalid.public static byte[] decodeBasic(char[] chars)
chars
- the character array to decode.NullPointerException
- if chars
is null
.IllegalArgumentException
- if chars
is invalid.public static byte[] decodeBasic(char[] chars, int offset, int length)
chars
- the character array to decode.offset
- the index of first character to decode.length
- the number of characters to decode.NullPointerException
- if chars
is null
.IllegalArgumentException
- if an argument is invalid.IndexOutOfBoundsException
- if an argument is out-of-bounds.public static byte[] decodeUrlSafe(String str)
str
- the string to decode.NullPointerException
- if str
is null
.IllegalArgumentException
- if str
is invalid.public static byte[] decodeUrlSafe(char[] chars)
chars
- the character array to decode.NullPointerException
- if chars
is null
.IllegalArgumentException
- if chars
is invalid.public static byte[] decodeUrlSafe(char[] chars, int offset, int length)
chars
- the character array to decode.offset
- the index of first character to decode.length
- the number of characters to decode.NullPointerException
- if chars
is null
.IllegalArgumentException
- if an argument is invalid.IndexOutOfBoundsException
- if an argument is out-of-bounds.public static byte[] decode(char[] chars, int offset, int length, boolean urlSafe)
chars
- the character array to decode.offset
- the index of first character to decode.length
- the number of characters to decode.urlSafe
- if true
use Base64 URL Safe decoding.NullPointerException
- if chars
is null
.IllegalArgumentException
- if an argument is invalid.IndexOutOfBoundsException
- if an argument is out-of-bounds.Copyright © OBCOM INGENIERIA S.A. (Chile). All Rights Reserved.