Added in [API level 8](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Constants](https://developer.android.com/reference/android/util/Base64#constants) \| [Methods](https://developer.android.com/reference/android/util/Base64#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/android/util/Base64#inhmethods)

# Base64

*** ** * ** ***


`
public


class
Base64
`


`

extends https://developer.android.com/reference/java/lang/Object


`

`


`

|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | android.util.Base64 |

<br />

*** ** * ** ***

Utilities for encoding and decoding the Base64 representation of
binary data. See RFCs [2045](http://www.ietf.org/rfc/rfc2045.txt) and [3548](http://www.ietf.org/rfc/rfc3548.txt).

## Summary

| ### Constants ||
|---|---|
| `int` | `https://developer.android.com/reference/android/util/Base64#CRLF` Encoder flag bit to indicate lines should be terminated with a CRLF pair instead of just an LF. |
| `int` | `https://developer.android.com/reference/android/util/Base64#DEFAULT` Default values for encoder/decoder flags. |
| `int` | `https://developer.android.com/reference/android/util/Base64#NO_CLOSE` Flag to pass to `https://developer.android.com/reference/android/util/Base64OutputStream` to indicate that it should not close the output stream it is wrapping when it itself is closed. |
| `int` | `https://developer.android.com/reference/android/util/Base64#NO_PADDING` Encoder flag bit to omit the padding '=' characters at the end of the output (if any). |
| `int` | `https://developer.android.com/reference/android/util/Base64#NO_WRAP` Encoder flag bit to omit all line terminators (i.e., the output will be on one long line). |
| `int` | `https://developer.android.com/reference/android/util/Base64#URL_SAFE` Encoder/decoder flag bit to indicate using the "URL and filename safe" variant of Base64 (see RFC 3548 section 4) where `-` and `_` are used in place of `+` and `/`. |

| ### Public methods ||
|---|---|
| ` static byte[]` | ` https://developer.android.com/reference/android/util/Base64#decode(java.lang.String,%20int)(https://developer.android.com/reference/java/lang/String str, int flags) ` Decode the Base64-encoded data in input and return the data in a new byte array. |
| ` static byte[]` | ` https://developer.android.com/reference/android/util/Base64#decode(byte[],%20int)(byte[] input, int flags) ` Decode the Base64-encoded data in input and return the data in a new byte array. |
| ` static byte[]` | ` https://developer.android.com/reference/android/util/Base64#decode(byte[],%20int,%20int,%20int)(byte[] input, int offset, int len, int flags) ` Decode the Base64-encoded data in input and return the data in a new byte array. |
| ` static byte[]` | ` https://developer.android.com/reference/android/util/Base64#encode(byte[],%20int)(byte[] input, int flags) ` Base64-encode the given data and return a newly allocated byte\[\] with the result. |
| ` static byte[]` | ` https://developer.android.com/reference/android/util/Base64#encode(byte[],%20int,%20int,%20int)(byte[] input, int offset, int len, int flags) ` Base64-encode the given data and return a newly allocated byte\[\] with the result. |
| ` static https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/android/util/Base64#encodeToString(byte[],%20int,%20int,%20int)(byte[] input, int offset, int len, int flags) ` Base64-encode the given data and return a newly allocated String with the result. |
| ` static https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/android/util/Base64#encodeToString(byte[],%20int)(byte[] input, int flags) ` Base64-encode the given data and return a newly allocated String with the result. |

| ### Inherited methods |
|---|---|
| From class ` https://developer.android.com/reference/java/lang/Object ` |---|---| | ` https://developer.android.com/reference/java/lang/Object` | ` https://developer.android.com/reference/java/lang/Object#clone()() ` Creates and returns a copy of this object. | | ` boolean` | ` https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj) ` Indicates whether some other object is "equal to" this one. | | ` void` | ` https://developer.android.com/reference/java/lang/Object#finalize()() ` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. | | ` final https://developer.android.com/reference/java/lang/Class<?>` | ` https://developer.android.com/reference/java/lang/Object#getClass()() ` Returns the runtime class of this `Object`. | | ` int` | ` https://developer.android.com/reference/java/lang/Object#hashCode()() ` Returns a hash code value for the object. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#notify()() ` Wakes up a single thread that is waiting on this object's monitor. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#notifyAll()() ` Wakes up all threads that are waiting on this object's monitor. | | ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/java/lang/Object#toString()() ` Returns a string representation of the object. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait(long,%20int)(long timeoutMillis, int nanos) ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait(long)(long timeoutMillis) ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait()() ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*. | ||

## Constants

### CRLF

Added in [API level 8](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int CRLF
```

Encoder flag bit to indicate lines should be terminated with a
CRLF pair instead of just an LF. Has no effect if `NO_WRAP` is specified as well.

<br />

Constant Value:

4
(0x00000004)


### DEFAULT

Added in [API level 8](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int DEFAULT
```

Default values for encoder/decoder flags.

<br />

Constant Value:

0
(0x00000000)


### NO_CLOSE

Added in [API level 8](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int NO_CLOSE
```

Flag to pass to `https://developer.android.com/reference/android/util/Base64OutputStream` to indicate that it
should not close the output stream it is wrapping when it
itself is closed.

<br />

Constant Value:

16
(0x00000010)


### NO_PADDING

Added in [API level 8](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int NO_PADDING
```

Encoder flag bit to omit the padding '=' characters at the end
of the output (if any).

<br />

Constant Value:

1
(0x00000001)


### NO_WRAP

Added in [API level 8](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int NO_WRAP
```

Encoder flag bit to omit all line terminators (i.e., the output
will be on one long line).

<br />

Constant Value:

2
(0x00000002)


### URL_SAFE

Added in [API level 8](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int URL_SAFE
```

Encoder/decoder flag bit to indicate using the "URL and
filename safe" variant of Base64 (see RFC 3548 section 4) where
`-` and `_` are used in place of `+` and
`/`.

<br />

Constant Value:

8
(0x00000008)


## Public methods

### decode

Added in [API level 8](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static byte[] decode (String str, 
                int flags)
```

Decode the Base64-encoded data in input and return the data in
a new byte array.

The padding '=' characters at the end are considered optional, but
if any are present, there must be the correct number of them.

<br />

| Parameters ||
|---|---|
| `str` | `String`: the input String to decode, which is converted to bytes using the default charset <br /> |
| `flags` | `int`: controls certain features of the decoded output. Pass `DEFAULT` to decode standard Base64. <br /> |

| Returns ||
|---|---|
| `byte[]` | <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | if the input contains incorrect padding |

### decode

Added in [API level 8](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static byte[] decode (byte[] input, 
                int flags)
```

Decode the Base64-encoded data in input and return the data in
a new byte array.

The padding '=' characters at the end are considered optional, but
if any are present, there must be the correct number of them.

<br />

| Parameters ||
|---|---|
| `input` | `byte`: the input array to decode <br /> |
| `flags` | `int`: controls certain features of the decoded output. Pass `DEFAULT` to decode standard Base64. <br /> |

| Returns ||
|---|---|
| `byte[]` | <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | if the input contains incorrect padding |

### decode

Added in [API level 8](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static byte[] decode (byte[] input, 
                int offset, 
                int len, 
                int flags)
```

Decode the Base64-encoded data in input and return the data in
a new byte array.

The padding '=' characters at the end are considered optional, but
if any are present, there must be the correct number of them.

<br />

| Parameters ||
|---|---|
| `input` | `byte`: the data to decode <br /> |
| `offset` | `int`: the position within the input array at which to start <br /> |
| `len` | `int`: the number of bytes of input to decode <br /> |
| `flags` | `int`: controls certain features of the decoded output. Pass `DEFAULT` to decode standard Base64. <br /> |

| Returns ||
|---|---|
| `byte[]` | <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | if the input contains incorrect padding |

### encode

Added in [API level 8](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static byte[] encode (byte[] input, 
                int flags)
```

Base64-encode the given data and return a newly allocated
byte\[\] with the result.

<br />

| Parameters ||
|---|---|
| `input` | `byte`: the data to encode <br /> |
| `flags` | `int`: controls certain features of the encoded output. Passing `DEFAULT` results in output that adheres to RFC 2045. <br /> |

| Returns ||
|---|---|
| `byte[]` | <br /> |

### encode

Added in [API level 8](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static byte[] encode (byte[] input, 
                int offset, 
                int len, 
                int flags)
```

Base64-encode the given data and return a newly allocated
byte\[\] with the result.

<br />

| Parameters ||
|---|---|
| `input` | `byte`: the data to encode <br /> |
| `offset` | `int`: the position within the input array at which to start <br /> |
| `len` | `int`: the number of bytes of input to encode <br /> |
| `flags` | `int`: controls certain features of the encoded output. Passing `DEFAULT` results in output that adheres to RFC 2045. <br /> |

| Returns ||
|---|---|
| `byte[]` | <br /> |

### encodeToString

Added in [API level 8](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static String encodeToString (byte[] input, 
                int offset, 
                int len, 
                int flags)
```

Base64-encode the given data and return a newly allocated
String with the result.

<br />

| Parameters ||
|---|---|
| `input` | `byte`: the data to encode <br /> |
| `offset` | `int`: the position within the input array at which to start <br /> |
| `len` | `int`: the number of bytes of input to encode <br /> |
| `flags` | `int`: controls certain features of the encoded output. Passing `DEFAULT` results in output that adheres to RFC 2045. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/String` | <br /> |

### encodeToString

Added in [API level 8](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static String encodeToString (byte[] input, 
                int flags)
```

Base64-encode the given data and return a newly allocated
String with the result.

<br />

| Parameters ||
|---|---|
| `input` | `byte`: the data to encode <br /> |
| `flags` | `int`: controls certain features of the encoded output. Passing `DEFAULT` results in output that adheres to RFC 2045. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/String` | <br /> |