1 Base64
This class consists exclusively of static methods for obtaining encoders and decoders for the Base64 encoding scheme.
Base64 as specified in RFC 4648 and RFC 2045.
-
Basic
Uses "The Base64 Alphabet" as specified in Table 1 of RFC 4648 and RFC 2045 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. -
MIME
Uses the "The Base64 Alphabet" as specified in Table 1 of RFC 2045 for encoding and decoding operation. The encoded output must be represented in lines of no more than 76 characters each and uses a carriage return '\r' followed immediately by a linefeed '\n' as the line separator. No line separator is added to the end of the encoded output. All line separators or other characters not found in the base64 alphabet table are ignored in decoding operation.
Copy
<script> var encode = Ax.util.Base64.encode("Hello world"); var decode = Ax.util.Base64.decode(encode); var print = new Ax.lang.String(decode); console.log(encode); console.log(print); </script>
SGVsbG8gd29ybGQ=
Hello world
It's important to use a character encoding format like "UTF-8" for special characters and it should be the same for encoding and decoding.
Special characters are sensitive in this case:
- For the first example, the same format is used in encoding and decoding which
is correct
.Copy<script> var encode = Ax.util.Base64.encode("á, é, í, ó, ú".getBytes("UTF-8")); var decode = Ax.util.Base64.decode(encode); var print = new Ax.lang.String(decode, "UTF-8"); console.log(print); </script>
á, é, í, ó, ú
- For the second example, a different encoding format is used than the decoding format which
results in an error
.Copy<script> var encode = Ax.util.Base64.encode("á, é, í, ó, ú".getBytes("ISO-8859-1")); var decode = Ax.util.Base64.decode(encode); var print = new Ax.lang.String(decode, "UTF-8"); console.log(print); </script>
�, �, �, �, �
Return | Method | Description |
---|---|---|
Basic | ||
byte[] | decode(String) | Basic decode |
byte[] | decode(byte[]) | Basic decode |
byte[] | decode(InputStream) | Basic decode |
String | encode(byte[]) | Basic encode |
URL and Filename safe | ||
byte[] | URLdecode(String) | URL decode |
byte[] | URLdecode(byte[]) | URL decode |
byte[] | URLdecode(InputStream) | URL decode |
String | URLencode(byte[]) | URL encode |
MIME | ||
byte[] | MIMEdecode(String) | MIME decode |
byte[] | MIMEdecode(byte[]) | MIME decode |
byte[] | MIMEdecode(InputStream) | MIME decode |
String | MIMEencode(byte[]) | MIME encode |