Skip to content

Most visited

Recently visited

navigation

Base64

public class Base64
extends Object

java.lang.Object
   ↳ java.util.Base64


This class consists exclusively of static methods for obtaining encoders and decoders for the Base64 encoding scheme. The implementation of this class supports the following types of 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.

Unless otherwise noted, passing a null argument to a method of this class will cause a NullPointerException to be thrown.

Summary

Nested classes

class Base64.Decoder

This class implements a decoder for decoding byte data using the Base64 encoding scheme as specified in RFC 4648 and RFC 2045. 

class Base64.Encoder

This class implements an encoder for encoding byte data using the Base64 encoding scheme as specified in RFC 4648 and RFC 2045. 

Public methods

static Base64.Decoder getDecoder()

Returns a Base64.Decoder that decodes using the Basic type base64 encoding scheme.

static Base64.Encoder getEncoder()

Returns a Base64.Encoder that encodes using the Basic type base64 encoding scheme.

static Base64.Decoder getMimeDecoder()

Returns a Base64.Decoder that decodes using the MIME type base64 decoding scheme.

static Base64.Encoder getMimeEncoder()

Returns a Base64.Encoder that encodes using the MIME type base64 encoding scheme.

static Base64.Encoder getMimeEncoder(int lineLength, byte[] lineSeparator)

Returns a Base64.Encoder that encodes using the MIME type base64 encoding scheme with specified line length and line separators.

static Base64.Decoder getUrlDecoder()

Returns a Base64.Decoder that decodes using the URL and Filename safe type base64 encoding scheme.

static Base64.Encoder getUrlEncoder()

Returns a Base64.Encoder that encodes using the URL and Filename safe type base64 encoding scheme.

Inherited methods

From class java.lang.Object

Public methods

getDecoder

added in API level 26
Base64.Decoder getDecoder ()

Returns a Base64.Decoder that decodes using the Basic type base64 encoding scheme.

Returns
Base64.Decoder A Base64 decoder.

getEncoder

added in API level 26
Base64.Encoder getEncoder ()

Returns a Base64.Encoder that encodes using the Basic type base64 encoding scheme.

Returns
Base64.Encoder A Base64 encoder.

getMimeDecoder

added in API level 26
Base64.Decoder getMimeDecoder ()

Returns a Base64.Decoder that decodes using the MIME type base64 decoding scheme.

Returns
Base64.Decoder A Base64 decoder.

getMimeEncoder

added in API level 26
Base64.Encoder getMimeEncoder ()

Returns a Base64.Encoder that encodes using the MIME type base64 encoding scheme.

Returns
Base64.Encoder A Base64 encoder.

getMimeEncoder

added in API level 26
Base64.Encoder getMimeEncoder (int lineLength, 
                byte[] lineSeparator)

Returns a Base64.Encoder that encodes using the MIME type base64 encoding scheme with specified line length and line separators.

Parameters
lineLength int: the length of each output line (rounded down to nearest multiple of 4). If lineLength <= 0 the output will not be separated in lines

lineSeparator byte: the line separator for each output line

Returns
Base64.Encoder A Base64 encoder.

Throws
IllegalArgumentException if lineSeparator includes any character of "The Base64 Alphabet" as specified in Table 1 of RFC 2045.

getUrlDecoder

added in API level 26
Base64.Decoder getUrlDecoder ()

Returns a Base64.Decoder that decodes using the URL and Filename safe type base64 encoding scheme.

Returns
Base64.Decoder A Base64 decoder.

getUrlEncoder

added in API level 26
Base64.Encoder getUrlEncoder ()

Returns a Base64.Encoder that encodes using the URL and Filename safe type base64 encoding scheme.

Returns
Base64.Encoder A Base64 encoder.

This site uses cookies to store your preferences for site-specific language and display options.

Get the latest Android developer news and tips that will help you find success on Google Play.

* Required Fields

Hooray!

Browse this site in ?

You requested a page in , but your language preference for this site is .

Would you like to change your language preference and browse this site in ? If you want to change your language preference later, use the language menu at the bottom of each page.

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.

Take a short survey?
Help us improve the Android developer experience.
(Sep 2017 survey)