this method seamlessly handles data encoded in URL-safe or normal mode.
Decodes a Base64 String into octets.
Note:
this method seamlessly handles data encoded in URL-safe or normal mode.
Parameters:
base64String
- String containing Base64 data
Returns:
Array containing decoded data.
Since:
decodeInteger
public static java.math.BigInteger decodeInteger(byte[] pArray)
Decodes a byte64-encoded integer according to crypto standards such as W3C's XML-Signature.
Parameters:
pArray
- a byte array containing base64 character data
Returns:
A BigInteger
Since:
encodeBase64
public static byte[] encodeBase64(byte[] binaryData)
Encodes binary data using the base64 algorithm but does not chunk the output.
Parameters:
binaryData
- binary data to encode
Returns:
byte[] containing Base64 characters in their UTF-8 representation.
public static byte[] encodeBase64(byte[] binaryData,
boolean isChunked)
Encodes binary data using the base64 algorithm, optionally chunking the output into 76 character blocks.
Parameters:
binaryData
- Array containing binary data to encode.
isChunked
- if
true
this encoder will chunk the base64 output into 76 character blocks
Returns:
Base64-encoded data.
Throws:
java.lang.IllegalArgumentException
- Thrown when the input array needs an output array bigger than
Integer.MAX_VALUE
boolean isChunked,
boolean urlSafe)
Encodes binary data using the base64 algorithm, optionally chunking the output into 76 character blocks.
Parameters:
binaryData
- Array containing binary data to encode.
isChunked
- if
true
this encoder will chunk the base64 output into 76 character blocks
urlSafe
- if
true
this encoder will emit - and _ instead of the usual + and / characters.
Note: no padding is added when encoding using the URL-safe alphabet.
Returns:
Base64-encoded data.
Throws:
java.lang.IllegalArgumentException
- Thrown when the input array needs an output array bigger than
Integer.MAX_VALUE
Since:
boolean urlSafe,
int maxResultSize)
Encodes binary data using the base64 algorithm, optionally chunking the output into 76 character blocks.
Parameters:
binaryData
- Array containing binary data to encode.
isChunked
- if
true
this encoder will chunk the base64 output into 76 character blocks
urlSafe
- if
true
this encoder will emit - and _ instead of the usual + and / characters.
Note: no padding is added when encoding using the URL-safe alphabet.
maxResultSize
- The maximum result size to accept.
Returns:
Base64-encoded data.
Throws:
java.lang.IllegalArgumentException
- Thrown when the input array needs an output array bigger than maxResultSize
Since:
encodeBase64Chunked
public static byte[] encodeBase64Chunked(byte[] binaryData)
Encodes binary data using the base64 algorithm and chunks the encoded output into 76 character blocks
Parameters:
binaryData
- binary data to encode
Returns:
Base64 characters chunked in 76 character blocks
encodeBase64String
public static java.lang.String encodeBase64String(byte[] binaryData)
Encodes binary data using the base64 algorithm but does not chunk the output.
NOTE: We changed the behavior of this method from multi-line chunking (commons-codec-1.4) to
single-line non-chunking (commons-codec-1.5).
Parameters:
binaryData
- binary data to encode
Returns:
String containing Base64 characters.
Since:
1.4 (NOTE: 1.4 chunked the output, whereas 1.5 does not).
encodeBase64URLSafe
public static byte[] encodeBase64URLSafe(byte[] binaryData)
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.
Parameters:
binaryData
- binary data to encode
Returns:
byte[] containing Base64 characters in their UTF-8 representation.
Since:
encodeBase64URLSafeString
public static java.lang.String encodeBase64URLSafeString(byte[] binaryData)
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.
Parameters:
binaryData
- binary data to encode
Returns:
String containing Base64 characters
Since:
encodeInteger
public static byte[] encodeInteger(java.math.BigInteger bigInteger)
Encodes to a byte64-encoded integer according to crypto standards such as W3C's XML-Signature.
Parameters:
bigInteger
- a BigInteger
Returns:
A byte array containing base64 character data
Throws:
java.lang.NullPointerException
- if null is passed in
Since:
isBase64
public static boolean isBase64(byte octet)
Returns whether or not the
octet
is in the base 64 alphabet.
Parameters:
octet
- The value to test
Returns:
true
if the value is defined in the the base 64 alphabet,
false
otherwise.
Since:
isBase64
public static boolean isBase64(byte[] arrayOctet)
Tests a given byte array to see if it contains only valid characters within the Base64 alphabet. Currently the
method treats whitespace as valid.
Parameters:
arrayOctet
- byte array to test
Returns:
true
if all bytes are valid characters in the Base64 alphabet or if the byte array is empty;
false
, otherwise
Since:
isBase64
public static boolean isBase64(java.lang.String base64)
Tests a given String to see if it contains only valid characters within the Base64 alphabet. Currently the
method treats whitespace as valid.
Parameters:
base64
- String to test
Returns:
true
if all characters in the String are valid characters in the Base64 alphabet or if
the String is empty;
false
, otherwise
Since:
isInAlphabet
protected boolean isInAlphabet(byte octet)
Returns whether or not the
octet
is in the Base64 alphabet.
Specified by:
isInAlphabet
in class
BaseNCodec
Parameters:
octet
- The value to test
Returns:
true
if the value is defined in the the Base64 alphabet
false
otherwise.
isUrlSafe
public boolean isUrlSafe()
Returns our current encode mode. True if we're URL-SAFE, false otherwise.
Returns:
true if we're in URL-SAFE mode, false otherwise.
Since: