public final class Base64
extends java.lang.Object
Lets encoding and decoding String with the Base64.
Note: To encode/decode stream of data, you can also use Base64InputStream and Base64OutputStream.
Examples:
public final static void main(final String[] args) throws Exception {
String message = "Hi ! If you can read this, the Base64 encoding/decoding has completely worked ! Well done ;-) !";
System.out.println("ORIGINAL MESSAGE:\n\""+message+"\"");
String encoded, decoded;
System.out.println("\nEncoding....");
encoded = Base64.encodeStr(message);
System.out.println("ENCODED MESSAGE:\n\""+encoded+"\"");
System.out.println("\nDecoding....");
decoded = Base64.decodeStr(encoded);
System.out.println("DECODED MESSAGE:\n\""+decoded+"\"");
}
| Modifier and Type | Method | Description |
|---|---|---|
static byte[] |
decode(char[] encoded) |
Decodes the given string which is supposed to be encoded in Base64.
|
static byte[] |
decode(java.lang.String encoded) |
Decodes the given string which is supposed to be encoded in Base64.
|
static java.lang.String |
decodeStr(java.lang.String encoded) |
Decodes the given string which is supposed to be encoded in Base64.
|
static java.lang.String |
decodeStr(java.lang.String encoded,
java.lang.String charset) |
Decodes the given string which is supposed to be encoded in Base64.
|
static java.lang.String |
encode(byte[] byteArray) |
Encodes the given bytes array in Base64 characters.
|
static java.lang.String |
encodeStr(java.lang.String string) |
Encodes the given string in Base64.
|
static java.lang.String |
encodeStr(java.lang.String string,
java.lang.String charset) |
Encodes the given string in Base64.
|
public static java.lang.String encodeStr(java.lang.String string)
string - The string to encode.encodeStr(String, String)public static java.lang.String encodeStr(java.lang.String string,
java.lang.String charset)
string - The string to encode (string supposed to be encoded with the given charset).charset - The name of a supported charset (i.e. 'UTF-8').encode(byte[])public static java.lang.String encode(byte[] byteArray)
byteArray - Data to encode.public static java.lang.String decodeStr(java.lang.String encoded)
throws Base64Exception
encoded - Message to decode.Base64Exception - If the encoded message is corrupted (that's to say: not conform to the Base64 encoding).decodeStr(String, String)public static java.lang.String decodeStr(java.lang.String encoded,
java.lang.String charset)
throws Base64Exception
encoded - Message to decode.charset - The name of a supported charset.charset).Base64Exception - If the encoded message is corrupted (that's to say: not conform to the Base64 encoding).decode(String)public static byte[] decode(java.lang.String encoded)
throws Base64Exception
encoded - Data to decode.Base64Exception - If the encoded data are corrupted (that's to say: not conform to the Base64 encoding).decode(char[])public static byte[] decode(char[] encoded)
throws Base64Exception
encoded - Data to decode.Base64Exception - If the encoded data are corrupted (that's to say: not conform to the Base64 encoding).