Public Member Functions | |
Base64 () | |
Base64 (final boolean urlSafe) | |
Base64 (final int lineLength) | |
Base64 (final int lineLength, final byte[] lineSeparator) | |
Base64 (final int lineLength, final byte[] lineSeparator, final boolean urlSafe) | |
boolean | isUrlSafe () |
![]() | |
Object | encode (final Object obj) throws EncoderException |
String | encodeToString (final byte[] pArray) |
String | encodeAsString (final byte[] pArray) |
Object | decode (final Object obj) throws DecoderException |
byte[] | decode (final String pArray) |
byte[] | decode (final byte[] pArray) |
byte[] | encode (final byte[] pArray) |
boolean | isInAlphabet (final byte[] arrayOctet, final boolean allowWSPad) |
boolean | isInAlphabet (final String basen) |
long | getEncodedLength (final byte[] pArray) |
![]() | |
byte[] | encode (byte[] source) throws EncoderException |
![]() | |
Object | encode (Object source) throws EncoderException |
![]() | |
byte[] | decode (byte[] source) throws DecoderException |
![]() | |
Object | decode (Object source) throws DecoderException |
Static Public Member Functions | |
static boolean | isArrayByteBase64 (final byte[] arrayOctet) |
static boolean | isBase64 (final byte octet) |
static boolean | isBase64 (final String base64) |
static boolean | isBase64 (final byte[] arrayOctet) |
static byte[] | encodeBase64 (final byte[] binaryData) |
static String | encodeBase64String (final byte[] binaryData) |
static byte[] | encodeBase64URLSafe (final byte[] binaryData) |
static String | encodeBase64URLSafeString (final byte[] binaryData) |
static byte[] | encodeBase64Chunked (final byte[] binaryData) |
static byte[] | encodeBase64 (final byte[] binaryData, final boolean isChunked) |
static byte[] | encodeBase64 (final byte[] binaryData, final boolean isChunked, final boolean urlSafe) |
static byte[] | encodeBase64 (final byte[] binaryData, final boolean isChunked, final boolean urlSafe, final int maxResultSize) |
static byte[] | decodeBase64 (final String base64String) |
static byte[] | decodeBase64 (final byte[] base64Data) |
static BigInteger | decodeInteger (final byte[] pArray) |
static byte[] | encodeInteger (final BigInteger bigInt) |
Protected Member Functions | |
boolean | isInAlphabet (final byte octet) |
![]() | |
BaseNCodec (final int unencodedBlockSize, final int encodedBlockSize, final int lineLength, final int chunkSeparatorLength) | |
int | getDefaultBufferSize () |
byte[] | ensureBufferSize (final int size, final Context context) |
abstract boolean | isInAlphabet (byte value) |
boolean | containsAlphabetOrPad (final byte[] arrayOctet) |
Package Functions | |
void | encode (final byte[] in, int inPos, final int inAvail, final Context context) |
void | decode (final byte[] in, int inPos, final int inAvail, final Context context) |
![]() | |
boolean | hasData (final Context context) |
int | available (final Context context) |
int | readResults (final byte[] b, final int bPos, final int bAvail, final Context context) |
abstract void | encode (byte[] pArray, int i, int length, Context context) |
abstract void | decode (byte[] pArray, int i, int length, Context context) |
Static Package Functions | |
static byte[] | toIntegerBytes (final BigInteger bigInt) |
Static Package Attributes | |
static final byte[] | CHUNK_SEPARATOR = {'\r', '\n'} |
![]() | |
static final int | EOF = -1 |
Private Attributes | |
final byte[] | encodeTable |
final byte[] | decodeTable = DECODE_TABLE |
final byte[] | lineSeparator |
final int | decodeSize |
final int | encodeSize |
Static Private Attributes | |
static final int | BITS_PER_ENCODED_BYTE = 6 |
static final int | BYTES_PER_UNENCODED_BLOCK = 3 |
static final int | BYTES_PER_ENCODED_BLOCK = 4 |
static final byte[] | STANDARD_ENCODE_TABLE |
static final byte[] | URL_SAFE_ENCODE_TABLE |
static final byte[] | DECODE_TABLE |
static final int | MASK_6BITS = 0x3f |
Additional Inherited Members | |
![]() | |
static final int | MIME_CHUNK_SIZE = 76 |
static final int | PEM_CHUNK_SIZE = 64 |
![]() | |
static boolean | isWhiteSpace (final byte byteToCheck) |
![]() | |
final byte | PAD = PAD_DEFAULT |
final int | lineLength |
![]() | |
static final int | MASK_8BITS = 0xff |
static final byte | PAD_DEFAULT = '=' |
Provides Base64 encoding and decoding as defined by RFC 2045.
This class implements section <cite>6.8. Base64 Content-Transfer-Encoding</cite> from RFC 2045 <cite>Multipurpose Internet Mail Extensions (MIME) Part One: Format of Internet Message Bodies</cite> by Freed and Borenstein.
The class can be parameterized in the following manner with various constructors:
Since this class operates directly on byte streams, and not character streams, it is hard-coded to only encode/decode character encodings which are compatible with the lower 127 ASCII chart (ISO-8859-1, Windows-1252, UTF-8, etc).
This class is thread-safe.
Definition at line 51 of file Base64.java.
org.apache.commons.codec.binary.Base64.Base64 | ( | ) |
Creates a Base64 codec used for decoding (all modes) and encoding in URL-unsafe mode.
When encoding the line length is 0 (no chunking), and the encoding table is STANDARD_ENCODE_TABLE.
When decoding all variants are supported.
Definition at line 169 of file Base64.java.
Referenced by org.apache.commons.codec.binary.Base64.decodeBase64(), and org.apache.commons.codec.binary.Base64.encodeBase64().
org.apache.commons.codec.binary.Base64.Base64 | ( | final boolean | urlSafe | ) |
Creates a Base64 codec used for decoding (all modes) and encoding in the given URL-safe mode.
When encoding the line length is 76, the line separator is CRLF, and the encoding table is STANDARD_ENCODE_TABLE.
When decoding all variants are supported.
urlSafe | if true
false
|
Definition at line 188 of file Base64.java.
References org.apache.commons.codec.binary.Base64.CHUNK_SEPARATOR, and org.apache.commons.codec.binary.BaseNCodec.MIME_CHUNK_SIZE.
org.apache.commons.codec.binary.Base64.Base64 | ( | final int | lineLength | ) |
Creates a Base64 codec used for decoding (all modes) and encoding in URL-unsafe mode.
When encoding the line length is given in the constructor, the line separator is CRLF, and the encoding table is STANDARD_ENCODE_TABLE.
Line lengths that aren't multiples of 4 will still essentially end up being multiples of 4 in the encoded data.
When decoding all variants are supported.
lineLength | Each line of encoded data will be at most of the given length (rounded down to nearest multiple of 4). If lineLength <= 0, then the output will not be divided into lines (chunks). Ignored when decoding. |
Definition at line 211 of file Base64.java.
References org.apache.commons.codec.binary.Base64.CHUNK_SEPARATOR, and org.apache.commons.codec.binary.BaseNCodec.lineLength.
org.apache.commons.codec.binary.Base64.Base64 | ( | final int | lineLength, |
final byte[] | lineSeparator | ||
) |
Creates a Base64 codec used for decoding (all modes) and encoding in URL-unsafe mode.
When encoding the line length and line separator are given in the constructor, and the encoding table is STANDARD_ENCODE_TABLE.
Line lengths that aren't multiples of 4 will still essentially end up being multiples of 4 in the encoded data.
When decoding all variants are supported.
lineLength | Each line of encoded data will be at most of the given length (rounded down to nearest multiple of 4). If lineLength <= 0, then the output will not be divided into lines (chunks). Ignored when decoding. |
lineSeparator | Each line of encoded data will end with this sequence of bytes. |
IllegalArgumentException | Thrown when the provided lineSeparator included some base64 characters. |
Definition at line 238 of file Base64.java.
References org.apache.commons.codec.binary.BaseNCodec.lineLength, and org.apache.commons.codec.binary.Base64.lineSeparator.
org.apache.commons.codec.binary.Base64.Base64 | ( | final int | lineLength, |
final byte[] | lineSeparator, | ||
final boolean | urlSafe | ||
) |
Creates a Base64 codec used for decoding (all modes) and encoding in URL-unsafe mode.
When encoding the line length and line separator are given in the constructor, and the encoding table is STANDARD_ENCODE_TABLE.
Line lengths that aren't multiples of 4 will still essentially end up being multiples of 4 in the encoded data.
When decoding all variants are supported.
lineLength | Each line of encoded data will be at most of the given length (rounded down to nearest multiple of 4). If lineLength <= 0, then the output will not be divided into lines (chunks). Ignored when decoding. |
lineSeparator | Each line of encoded data will end with this sequence of bytes. |
urlSafe | Instead of emitting '+' and '/' we emit '-' and '_' respectively. urlSafe is only applied to encode operations. Decoding seamlessly handles both modes. Note: no padding is added when using the URL-safe alphabet. |
IllegalArgumentException | The provided lineSeparator included some base64 characters. That's not going to work! |
Definition at line 269 of file Base64.java.
References org.apache.commons.codec.binary.Base64.BYTES_PER_ENCODED_BLOCK, org.apache.commons.codec.binary.BaseNCodec.containsAlphabetOrPad(), org.apache.commons.codec.binary.StringUtils.newStringUtf8(), and org.apache.commons.codec.binary.Base64.STANDARD_ENCODE_TABLE.
|
package |
Decodes all of the provided data, starting at inPos, for inAvail bytes. Should be called at least twice: once with the data to decode, and once with inAvail set to "-1" to alert decoder that EOF has been reached. The "-1" call is not necessary when decoding, but it doesn't hurt, either.
Ignores all non-base64 characters. This is how chunked (e.g. 76 character) data is handled, since CR and LF are silently ignored, but has implications for other bytes, too. This method subscribes to the garbage-in, garbage-out philosophy: it will not check the provided data for validity.
Thanks to "commons" project in ws.apache.org for the bitwise operations, and general approach. http://svn.apache.org/repos/asf/webservices/commons/trunk/modules/util/
in | byte[] array of ascii data to base64 decode. |
inPos | Position to start reading data from. |
inAvail | Amount of bytes available from input for encoding. |
context | the context to be used |
Definition at line 425 of file Base64.java.
References org.apache.commons.codec.binary.Base64.BITS_PER_ENCODED_BYTE, org.apache.commons.codec.binary.BaseNCodec.ensureBufferSize(), org.apache.commons.codec.binary.BaseNCodec.Context.eof, org.apache.commons.codec.binary.BaseNCodec.Context.ibitWorkArea, org.apache.commons.codec.binary.BaseNCodec.MASK_8BITS, org.apache.commons.codec.binary.BaseNCodec.Context.modulus, org.apache.commons.codec.binary.BaseNCodec.PAD, org.apache.commons.codec.binary.BaseNCodec.Context.pos, and webiopi.utils.version.result.
|
static |
Decodes a Base64 String into octets
base64String | String containing Base64 data |
Definition at line 685 of file Base64.java.
References org.apache.commons.codec.binary.Base64.Base64().
Referenced by org.apache.commons.codec.binary.Base64.decodeInteger().
|
static |
Decodes Base64 data into octets
base64Data | Byte array containing Base64 data |
Definition at line 696 of file Base64.java.
References org.apache.commons.codec.binary.Base64.Base64().
|
static |
Decodes a byte64-encoded integer according to crypto standards such as W3C's XML-Signature
pArray | a byte array containing base64 character data |
Definition at line 711 of file Base64.java.
References org.apache.commons.codec.binary.Base64.decodeBase64().
|
package |
Encodes all of the provided data, starting at inPos, for inAvail bytes. Must be called at least twice: once with the data to encode, and once with inAvail set to "-1" to alert encoder that EOF has been reached, to flush last remaining bytes (if not multiple of 3).
Note: no padding is added when encoding using the URL-safe alphabet.
Thanks to "commons" project in ws.apache.org for the bitwise operations, and general approach. http://svn.apache.org/repos/asf/webservices/commons/trunk/modules/util/
in | byte[] array of binary data to base64 encode. |
inPos | Position to start reading data from. |
inAvail | Amount of bytes available from input for encoding. |
context | the context to be used |
Definition at line 328 of file Base64.java.
References org.apache.commons.codec.binary.Base64.BYTES_PER_ENCODED_BLOCK, org.apache.commons.codec.binary.BaseNCodec.Context.currentLinePos, org.apache.commons.codec.binary.BaseNCodec.ensureBufferSize(), org.apache.commons.codec.binary.BaseNCodec.Context.eof, org.apache.commons.codec.binary.BaseNCodec.Context.ibitWorkArea, org.apache.commons.codec.binary.BaseNCodec.lineLength, org.apache.commons.codec.binary.Base64.MASK_6BITS, org.apache.commons.codec.binary.BaseNCodec.Context.modulus, org.apache.commons.codec.binary.BaseNCodec.PAD, and org.apache.commons.codec.binary.BaseNCodec.Context.pos.
Referenced by org.apache.commons.codec.binary.Base64.encodeBase64().
|
static |
Encodes binary data using the base64 algorithm but does not chunk the output.
binaryData | binary data to encode |
Definition at line 550 of file Base64.java.
Referenced by org.apache.commons.codec.binary.Base64.encodeBase64(), org.apache.commons.codec.binary.Base64.encodeBase64Chunked(), org.apache.commons.codec.binary.Base64.encodeBase64String(), org.apache.commons.codec.binary.Base64.encodeBase64URLSafe(), org.apache.commons.codec.binary.Base64.encodeBase64URLSafeString(), and org.apache.commons.codec.binary.Base64.encodeInteger().
|
static |
Encodes binary data using the base64 algorithm, optionally chunking the output into 76 character blocks.
binaryData | Array containing binary data to encode. |
isChunked | if true
|
IllegalArgumentException | Thrown when the input array needs an output array bigger than Integer#MAX_VALUE |
Definition at line 617 of file Base64.java.
References org.apache.commons.codec.binary.Base64.encodeBase64().
|
static |
Encodes binary data using the base64 algorithm, optionally chunking the output into 76 character blocks.
binaryData | Array containing binary data to encode. |
isChunked | if true
|
urlSafe | if true
|
IllegalArgumentException | Thrown when the input array needs an output array bigger than Integer#MAX_VALUE |
Definition at line 636 of file Base64.java.
References org.apache.commons.codec.binary.Base64.encodeBase64().
|
static |
Encodes binary data using the base64 algorithm, optionally chunking the output into 76 character blocks.
binaryData | Array containing binary data to encode. |
isChunked | if true
|
urlSafe | if true
|
maxResultSize | The maximum result size to accept. |
IllegalArgumentException | Thrown when the input array needs an output array bigger than maxResultSize |
Definition at line 657 of file Base64.java.
References org.apache.commons.codec.binary.Base64.Base64(), org.apache.commons.codec.binary.Base64.encode(), and org.apache.commons.codec.binary.BaseNCodec.getEncodedLength().
|
static |
Encodes binary data using the base64 algorithm and chunks the encoded output into 76 character blocks
binaryData | binary data to encode |
Definition at line 602 of file Base64.java.
References org.apache.commons.codec.binary.Base64.encodeBase64().
|
static |
Encodes binary data using the base64 algorithm but does not chunk the output.
NOTE: We changed the behaviour of this method from multi-line chunking (commons-codec-1.4) to single-line non-chunking (commons-codec-1.5).
binaryData | binary data to encode |
Definition at line 565 of file Base64.java.
References org.apache.commons.codec.binary.Base64.encodeBase64(), and org.apache.commons.codec.binary.StringUtils.newStringUtf8().
Referenced by com.trouch.webiopi.client.PiClient.encodeCredentials().
|
static |
Encodes binary data using a URL-safe variation of the base64 algorithm but does not chunk the output. The url-safe variation emits - and _ instead of + and / characters. Note: no padding is added.
binaryData | binary data to encode |
Definition at line 578 of file Base64.java.
References org.apache.commons.codec.binary.Base64.encodeBase64().
|
static |
Encodes binary data using a URL-safe variation of the base64 algorithm but does not chunk the output. The url-safe variation emits - and _ instead of + and / characters. Note: no padding is added.
binaryData | binary data to encode |
Definition at line 591 of file Base64.java.
References org.apache.commons.codec.binary.Base64.encodeBase64(), and org.apache.commons.codec.binary.StringUtils.newStringUtf8().
|
static |
Encodes to a byte64-encoded integer according to crypto standards such as W3C's XML-Signature
bigInt | a BigInteger |
NullPointerException | if null is passed in |
Definition at line 725 of file Base64.java.
References org.apache.commons.codec.binary.Base64.encodeBase64(), and org.apache.commons.codec.binary.Base64.toIntegerBytes().
|
static |
Tests a given byte array to see if it contains only valid characters within the Base64 alphabet. Currently the method treats whitespace as valid.
arrayOctet | byte array to test |
Definition at line 494 of file Base64.java.
References org.apache.commons.codec.binary.Base64.isBase64().
|
static |
Returns whether or not the octet
is in the base 64 alphabet.
octet | The value to test |
Definition at line 506 of file Base64.java.
References org.apache.commons.codec.binary.BaseNCodec.PAD_DEFAULT.
Referenced by org.apache.commons.codec.binary.Base64.isArrayByteBase64(), and org.apache.commons.codec.binary.Base64.isBase64().
|
static |
Tests a given String to see if it contains only valid characters within the Base64 alphabet. Currently the method treats whitespace as valid.
base64 | String to test |
Definition at line 520 of file Base64.java.
References org.apache.commons.codec.binary.StringUtils.getBytesUtf8(), and org.apache.commons.codec.binary.Base64.isBase64().
|
static |
Tests a given byte array to see if it contains only valid characters within the Base64 alphabet. Currently the method treats whitespace as valid.
arrayOctet | byte array to test |
Definition at line 534 of file Base64.java.
References org.apache.commons.codec.binary.Base64.isBase64(), and org.apache.commons.codec.binary.BaseNCodec.isWhiteSpace().
|
protected |
Returns whether or not the octet
is in the Base64 alphabet.
octet | The value to test |
Definition at line 771 of file Base64.java.
boolean org.apache.commons.codec.binary.Base64.isUrlSafe | ( | ) |
Returns our current encode mode. True if we're URL-SAFE, false otherwise.
Definition at line 302 of file Base64.java.
References org.apache.commons.codec.binary.Base64.URL_SAFE_ENCODE_TABLE.
|
staticpackage |
Returns a byte-array representation of a BigInteger
without sign bit.
bigInt | BigInteger to be converted |
Definition at line 739 of file Base64.java.
Referenced by org.apache.commons.codec.binary.Base64.encodeInteger().
|
staticprivate |
BASE32 characters are 6 bits in length. They are formed by taking a block of 3 octets to form a 24-bit string, which is converted into 4 BASE64 characters.
Definition at line 58 of file Base64.java.
Referenced by org.apache.commons.codec.binary.Base64.decode().
|
staticprivate |
Definition at line 60 of file Base64.java.
Referenced by org.apache.commons.codec.binary.Base64.Base64(), and org.apache.commons.codec.binary.Base64.encode().
|
staticprivate |
Definition at line 59 of file Base64.java.
|
staticpackage |
Chunk separator per RFC 2045 section 2.1.
N.B. The next major release may break compatibility and make this field private.
Definition at line 71 of file Base64.java.
Referenced by org.apache.commons.codec.binary.Base64.Base64().
|
staticprivate |
This array is a lookup table that translates Unicode characters drawn from the "Base64 Alphabet" (as specified in Table 1 of RFC 2045) into their 6-bit positive integer equivalents. Characters that are not in the Base64 alphabet but fall within the bounds of the array are translated to -1.
Note: '+' and '-' both decode to 62. '/' and '_' both decode to 63. This means decoder seamlessly handles both URL_SAFE and STANDARD base64. (The encoder, on the other hand, needs to know ahead of time what to emit).
Thanks to "commons" project in ws.apache.org for this code. http://svn.apache.org/repos/asf/webservices/commons/trunk/modules/util/
Definition at line 112 of file Base64.java.
|
private |
Convenience variable to help us determine when our buffer is going to run out of room and needs resizing. decodeSize = 3 + lineSeparator.length;
Definition at line 151 of file Base64.java.
|
private |
Definition at line 140 of file Base64.java.
|
private |
Convenience variable to help us determine when our buffer is going to run out of room and needs resizing. encodeSize = 4 + lineSeparator.length;
Definition at line 157 of file Base64.java.
|
private |
Encode table to use: either STANDARD or URL_SAFE. Note: the DECODE_TABLE above remains static because it is able to decode both STANDARD and URL_SAFE streams, but the encodeTable must be a member variable so we can switch between the two modes.
Definition at line 137 of file Base64.java.
|
private |
Line separator for encoding. Not used when decoding. Only used if lineLength > 0.
Definition at line 145 of file Base64.java.
Referenced by org.apache.commons.codec.binary.Base64.Base64().
|
staticprivate |
Base64 uses 6-bit fields.Mask used to extract 6 bits, used when encoding
Definition at line 126 of file Base64.java.
Referenced by org.apache.commons.codec.binary.Base64.encode().
|
staticprivate |
This array is a lookup table that translates 6-bit positive integer index values into their "Base64 Alphabet" equivalents as specified in Table 1 of RFC 2045.
Thanks to "commons" project in ws.apache.org for this code. http://svn.apache.org/repos/asf/webservices/commons/trunk/modules/util/
Definition at line 80 of file Base64.java.
Referenced by org.apache.commons.codec.binary.Base64.Base64().
|
staticprivate |
This is a copy of the STANDARD_ENCODE_TABLE above, but with + and / changed to - and _ to make the encoded Base64 results more URL-SAFE. This table is only used when the Base64's mode is set to URL-SAFE.
Definition at line 93 of file Base64.java.
Referenced by org.apache.commons.codec.binary.Base64.isUrlSafe().