Added in [API level 28](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Constants](https://developer.android.com/reference/android/net/IpSecAlgorithm#constants) \| [Inherited Constants](https://developer.android.com/reference/android/net/IpSecAlgorithm#inhconstants) \| [Fields](https://developer.android.com/reference/android/net/IpSecAlgorithm#lfields) \| [Ctors](https://developer.android.com/reference/android/net/IpSecAlgorithm#pubctors) \| [Methods](https://developer.android.com/reference/android/net/IpSecAlgorithm#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/android/net/IpSecAlgorithm#inhmethods)

# IpSecAlgorithm

*** ** * ** ***


`
public

final

class
IpSecAlgorithm
`


`

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


`

`


implements

https://developer.android.com/reference/android/os/Parcelable


`

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

<br />

*** ** * ** ***

This class represents a single algorithm that can be used by an `https://developer.android.com/reference/android/net/IpSecTransform`.
**See also:**

- [RFC 4301, Security Architecture for the
  Internet Protocol](https://tools.ietf.org/html/rfc4301)

## Summary

| ### Constants ||
|---|---|
| `https://developer.android.com/reference/java/lang/String` | `https://developer.android.com/reference/android/net/IpSecAlgorithm#AUTH_AES_CMAC` AES-CMAC Authentication/Integrity Algorithm. |
| `https://developer.android.com/reference/java/lang/String` | `https://developer.android.com/reference/android/net/IpSecAlgorithm#AUTH_AES_XCBC` AES-XCBC Authentication/Integrity Algorithm. |
| `https://developer.android.com/reference/java/lang/String` | `https://developer.android.com/reference/android/net/IpSecAlgorithm#AUTH_CRYPT_AES_GCM` AES-GCM Authentication/Integrity + Encryption/Ciphering Algorithm. |
| `https://developer.android.com/reference/java/lang/String` | `https://developer.android.com/reference/android/net/IpSecAlgorithm#AUTH_CRYPT_CHACHA20_POLY1305` ChaCha20-Poly1305 Authentication/Integrity + Encryption/Ciphering Algorithm. |
| `https://developer.android.com/reference/java/lang/String` | `https://developer.android.com/reference/android/net/IpSecAlgorithm#AUTH_HMAC_MD5` MD5 HMAC Authentication/Integrity Algorithm. |
| `https://developer.android.com/reference/java/lang/String` | `https://developer.android.com/reference/android/net/IpSecAlgorithm#AUTH_HMAC_SHA1` SHA1 HMAC Authentication/Integrity Algorithm. |
| `https://developer.android.com/reference/java/lang/String` | `https://developer.android.com/reference/android/net/IpSecAlgorithm#AUTH_HMAC_SHA256` SHA256 HMAC Authentication/Integrity Algorithm. |
| `https://developer.android.com/reference/java/lang/String` | `https://developer.android.com/reference/android/net/IpSecAlgorithm#AUTH_HMAC_SHA384` SHA384 HMAC Authentication/Integrity Algorithm. |
| `https://developer.android.com/reference/java/lang/String` | `https://developer.android.com/reference/android/net/IpSecAlgorithm#AUTH_HMAC_SHA512` SHA512 HMAC Authentication/Integrity Algorithm. |
| `https://developer.android.com/reference/java/lang/String` | `https://developer.android.com/reference/android/net/IpSecAlgorithm#CRYPT_AES_CBC` AES-CBC Encryption/Ciphering Algorithm. |
| `https://developer.android.com/reference/java/lang/String` | `https://developer.android.com/reference/android/net/IpSecAlgorithm#CRYPT_AES_CTR` AES-CTR Encryption/Ciphering Algorithm. |

### Inherited constants

From interface `https://developer.android.com/reference/android/os/Parcelable` `int` `https://developer.android.com/reference/android/os/Parcelable#CONTENTS_FILE_DESCRIPTOR`

Descriptor bit used with `https://developer.android.com/reference/android/os/Parcelable#describeContents()`: indicates that
the Parcelable object's flattened representation includes a file descriptor.


`int` `https://developer.android.com/reference/android/os/Parcelable#PARCELABLE_WRITE_RETURN_VALUE`

Flag for use with `https://developer.android.com/reference/android/os/Parcelable#writeToParcel(android.os.Parcel,%20int)`: the object being written
is a return value, that is the result of a function such as
"`Parcelable someFunction()`",
"`void someFunction(out Parcelable)`", or
"`void someFunction(inout Parcelable)`".


| ### Fields ||
|---|---|
| ` public static final https://developer.android.com/reference/android/os/Parcelable.Creator<https://developer.android.com/reference/android/net/IpSecAlgorithm>` | `https://developer.android.com/reference/android/net/IpSecAlgorithm#CREATOR` Parcelable Creator |

| ### Public constructors ||
|---|---|
| ` https://developer.android.com/reference/android/net/IpSecAlgorithm#IpSecAlgorithm(java.lang.String,%20byte[])(https://developer.android.com/reference/java/lang/String algorithm, byte[] key) ` Creates an IpSecAlgorithm of one of the supported types. |
| ` https://developer.android.com/reference/android/net/IpSecAlgorithm#IpSecAlgorithm(java.lang.String,%20byte[],%20int)(https://developer.android.com/reference/java/lang/String algorithm, byte[] key, int truncLenBits) ` Creates an IpSecAlgorithm of one of the supported types. |

| ### Public methods ||
|---|---|
| ` int` | ` https://developer.android.com/reference/android/net/IpSecAlgorithm#describeContents()() ` Parcelable Implementation |
| ` byte[]` | ` https://developer.android.com/reference/android/net/IpSecAlgorithm#getKey()() ` Get the key for this algorithm |
| ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/android/net/IpSecAlgorithm#getName()() ` Get the algorithm name |
| ` static https://developer.android.com/reference/java/util/Set<https://developer.android.com/reference/java/lang/String>` | ` https://developer.android.com/reference/android/net/IpSecAlgorithm#getSupportedAlgorithms()() ` Returns supported IPsec algorithms for the current device. |
| ` int` | ` https://developer.android.com/reference/android/net/IpSecAlgorithm#getTruncationLengthBits()() ` Get the truncation length of this algorithm, in bits |
| ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/android/net/IpSecAlgorithm#toString()() ` Returns a string representation of the object. |
| ` void` | ` https://developer.android.com/reference/android/net/IpSecAlgorithm#writeToParcel(android.os.Parcel,%20int)(https://developer.android.com/reference/android/os/Parcel out, int flags) ` Write to parcel |

### 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*.


From interface `

https://developer.android.com/reference/android/os/Parcelable

` `
abstract


int` `
https://developer.android.com/reference/android/os/Parcelable#describeContents()()
`

Describe the kinds of special objects contained in this Parcelable
instance's marshaled representation.


`
abstract


void` `
https://developer.android.com/reference/android/os/Parcelable#writeToParcel(android.os.Parcel,%20int)(https://developer.android.com/reference/android/os/Parcel dest, int flags)
`

Flatten this object in to a Parcel.


## Constants

### AUTH_AES_CMAC

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

```
public static final String AUTH_AES_CMAC
```

AES-CMAC Authentication/Integrity Algorithm.

Keys for this algorithm must be 128 bits in length.

The only valid truncation length is 96 bits.

This algorithm may be available on the device. Caller MUST check if it is supported before
using it by calling `https://developer.android.com/reference/android/net/IpSecAlgorithm#getSupportedAlgorithms()` and checking if this algorithm is
included in the returned algorithm set. The returned algorithm set will not change unless the
device is rebooted. `https://developer.android.com/reference/java/lang/IllegalArgumentException` will be thrown if this algorithm is
requested on an unsupported device.

<br />

**See also:**

- `https://developer.android.com/reference/android/net/IpSecAlgorithm#getSupportedAlgorithms()`

Constant Value:

"cmac(aes)"


### AUTH_AES_XCBC

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

```
public static final String AUTH_AES_XCBC
```

AES-XCBC Authentication/Integrity Algorithm.

Keys for this algorithm must be 128 bits in length.

The only valid truncation length is 96 bits.

This algorithm may be available on the device. Caller MUST check if it is supported before
using it by calling `https://developer.android.com/reference/android/net/IpSecAlgorithm#getSupportedAlgorithms()` and checking if this algorithm is
included in the returned algorithm set. The returned algorithm set will not change unless the
device is rebooted. `https://developer.android.com/reference/java/lang/IllegalArgumentException` will be thrown if this algorithm is
requested on an unsupported device.

<br />

**See also:**

- `https://developer.android.com/reference/android/net/IpSecAlgorithm#getSupportedAlgorithms()`

Constant Value:

"xcbc(aes)"


### AUTH_CRYPT_AES_GCM

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

```
public static final String AUTH_CRYPT_AES_GCM
```

AES-GCM Authentication/Integrity + Encryption/Ciphering Algorithm.

Valid lengths for keying material are {160, 224, 288}.

As per [RFC4106 (Section
8.1)](https://tools.ietf.org/html/rfc4106#section-8.1), keying material consists of a 128, 192, or 256 bit AES key followed by a 32-bit
salt. RFC compliance requires that the salt must be unique per invocation with the same key.

Valid ICV (truncation) lengths are {64, 96, 128}.

<br />

Constant Value:

"rfc4106(gcm(aes))"


### AUTH_CRYPT_CHACHA20_POLY1305

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

```
public static final String AUTH_CRYPT_CHACHA20_POLY1305
```

ChaCha20-Poly1305 Authentication/Integrity + Encryption/Ciphering Algorithm.

Keys for this algorithm must be 288 bits in length.

As per [RFC7634 (Section 2)](https://tools.ietf.org/html/rfc7634#section-2),
keying material consists of a 256 bit key followed by a 32-bit salt. The salt is fixed per
security association.

The only valid ICV (truncation) length is 128 bits.

This algorithm may be available on the device. Caller MUST check if it is supported before
using it by calling `https://developer.android.com/reference/android/net/IpSecAlgorithm#getSupportedAlgorithms()` and checking if this algorithm is
included in the returned algorithm set. The returned algorithm set will not change unless the
device is rebooted. `https://developer.android.com/reference/java/lang/IllegalArgumentException` will be thrown if this algorithm is
requested on an unsupported device.

<br />

**See also:**

- `https://developer.android.com/reference/android/net/IpSecAlgorithm#getSupportedAlgorithms()`

Constant Value:

"rfc7539esp(chacha20,poly1305)"


### AUTH_HMAC_MD5

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

```
public static final String AUTH_HMAC_MD5
```

MD5 HMAC Authentication/Integrity Algorithm. **This algorithm is not recommended for use in
new applications and is provided for legacy compatibility with 3gpp infrastructure.**

Keys for this algorithm must be 128 bits in length.

Valid truncation lengths are multiples of 8 bits from 96 to 128.

<br />

Constant Value:

"hmac(md5)"


### AUTH_HMAC_SHA1

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

```
public static final String AUTH_HMAC_SHA1
```

SHA1 HMAC Authentication/Integrity Algorithm. **This algorithm is not recommended for use in
new applications and is provided for legacy compatibility with 3gpp infrastructure.**

Keys for this algorithm must be 160 bits in length.

Valid truncation lengths are multiples of 8 bits from 96 to 160.

<br />

Constant Value:

"hmac(sha1)"


### AUTH_HMAC_SHA256

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

```
public static final String AUTH_HMAC_SHA256
```

SHA256 HMAC Authentication/Integrity Algorithm.

Keys for this algorithm must be 256 bits in length.

Valid truncation lengths are multiples of 8 bits from 96 to 256.

<br />

Constant Value:

"hmac(sha256)"


### AUTH_HMAC_SHA384

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

```
public static final String AUTH_HMAC_SHA384
```

SHA384 HMAC Authentication/Integrity Algorithm.

Keys for this algorithm must be 384 bits in length.

Valid truncation lengths are multiples of 8 bits from 192 to 384.

<br />

Constant Value:

"hmac(sha384)"


### AUTH_HMAC_SHA512

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

```
public static final String AUTH_HMAC_SHA512
```

SHA512 HMAC Authentication/Integrity Algorithm.

Keys for this algorithm must be 512 bits in length.

Valid truncation lengths are multiples of 8 bits from 256 to 512.

<br />

Constant Value:

"hmac(sha512)"


### CRYPT_AES_CBC

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

```
public static final String CRYPT_AES_CBC
```

AES-CBC Encryption/Ciphering Algorithm.

Valid lengths for this key are {128, 192, 256}.

<br />

Constant Value:

"cbc(aes)"


### CRYPT_AES_CTR

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

```
public static final String CRYPT_AES_CTR
```

AES-CTR Encryption/Ciphering Algorithm.

Valid lengths for keying material are {160, 224, 288}.

As per [RFC3686 (Section
5.1)](https://tools.ietf.org/html/rfc3686#section-5.1), keying material consists of a 128, 192, or 256 bit AES key followed by a 32-bit
nonce. RFC compliance requires that the nonce must be unique per security association.

This algorithm may be available on the device. Caller MUST check if it is supported before
using it by calling `https://developer.android.com/reference/android/net/IpSecAlgorithm#getSupportedAlgorithms()` and checking if this algorithm is
included in the returned algorithm set. The returned algorithm set will not change unless the
device is rebooted. `https://developer.android.com/reference/java/lang/IllegalArgumentException` will be thrown if this algorithm is
requested on an unsupported device.

<br />

**See also:**

- `https://developer.android.com/reference/android/net/IpSecAlgorithm#getSupportedAlgorithms()`

Constant Value:

"rfc3686(ctr(aes))"


## Fields

### CREATOR

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

```
public static final Creator<IpSecAlgorithm> CREATOR
```

Parcelable Creator

<br />

## Public constructors

### IpSecAlgorithm

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

```
public IpSecAlgorithm (String algorithm, 
                byte[] key)
```

Creates an IpSecAlgorithm of one of the supported types. Supported algorithm names are
defined as constants in this class.

For algorithms that produce an integrity check value, the truncation length is a required
parameter. See `https://developer.android.com/reference/android/net/IpSecAlgorithm#IpSecAlgorithm(java.lang.String,%20byte[],%20int)`

<br />

| Parameters ||
|---|---|
| `algorithm` | `String`: name of the algorithm. This value cannot be `null`. Value is one of the following: - `https://developer.android.com/reference/android/net/IpSecAlgorithm#CRYPT_AES_CBC` - `https://developer.android.com/reference/android/net/IpSecAlgorithm#CRYPT_AES_CTR` - `https://developer.android.com/reference/android/net/IpSecAlgorithm#AUTH_HMAC_MD5` - `https://developer.android.com/reference/android/net/IpSecAlgorithm#AUTH_HMAC_SHA1` - `https://developer.android.com/reference/android/net/IpSecAlgorithm#AUTH_HMAC_SHA256` - `https://developer.android.com/reference/android/net/IpSecAlgorithm#AUTH_HMAC_SHA384` - `https://developer.android.com/reference/android/net/IpSecAlgorithm#AUTH_HMAC_SHA512` - `https://developer.android.com/reference/android/net/IpSecAlgorithm#AUTH_AES_XCBC` - `https://developer.android.com/reference/android/net/IpSecAlgorithm#AUTH_AES_CMAC` - `https://developer.android.com/reference/android/net/IpSecAlgorithm#AUTH_CRYPT_AES_GCM` - `https://developer.android.com/reference/android/net/IpSecAlgorithm#AUTH_CRYPT_CHACHA20_POLY1305` |
| `key` | `byte`: key padded to a multiple of 8 bits. This value cannot be `null`. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | if algorithm or key length is invalid. |

### IpSecAlgorithm

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

```
public IpSecAlgorithm (String algorithm, 
                byte[] key, 
                int truncLenBits)
```

Creates an IpSecAlgorithm of one of the supported types. Supported algorithm names are
defined as constants in this class.

This constructor only supports algorithms that use a truncation length. i.e.
Authentication and Authenticated Encryption algorithms.

<br />

| Parameters ||
|---|---|
| `algorithm` | `String`: name of the algorithm. This value cannot be `null`. Value is one of the following: - `https://developer.android.com/reference/android/net/IpSecAlgorithm#CRYPT_AES_CBC` - `https://developer.android.com/reference/android/net/IpSecAlgorithm#CRYPT_AES_CTR` - `https://developer.android.com/reference/android/net/IpSecAlgorithm#AUTH_HMAC_MD5` - `https://developer.android.com/reference/android/net/IpSecAlgorithm#AUTH_HMAC_SHA1` - `https://developer.android.com/reference/android/net/IpSecAlgorithm#AUTH_HMAC_SHA256` - `https://developer.android.com/reference/android/net/IpSecAlgorithm#AUTH_HMAC_SHA384` - `https://developer.android.com/reference/android/net/IpSecAlgorithm#AUTH_HMAC_SHA512` - `https://developer.android.com/reference/android/net/IpSecAlgorithm#AUTH_AES_XCBC` - `https://developer.android.com/reference/android/net/IpSecAlgorithm#AUTH_AES_CMAC` - `https://developer.android.com/reference/android/net/IpSecAlgorithm#AUTH_CRYPT_AES_GCM` - `https://developer.android.com/reference/android/net/IpSecAlgorithm#AUTH_CRYPT_CHACHA20_POLY1305` |
| `key` | `byte`: key padded to a multiple of 8 bits. This value cannot be `null`. <br /> |
| `truncLenBits` | `int`: number of bits of output hash to use. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | if algorithm, key length or truncation length is invalid. |

## Public methods

### describeContents

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

```
public int describeContents ()
```

Parcelable Implementation

<br />

| Returns ||
|---|---|
| `int` | a bitmask indicating the set of special object types marshaled by this Parcelable object instance. Value is either `0` or - `https://developer.android.com/reference/android/os/Parcelable#CONTENTS_FILE_DESCRIPTOR` |

### getKey

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

```
public byte[] getKey ()
```

Get the key for this algorithm

<br />

| Returns ||
|---|---|
| `byte[]` | This value cannot be `null`. <br /> |

### getName

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

```
public String getName ()
```

Get the algorithm name

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/String` | This value cannot be `null`. <br /> |

### getSupportedAlgorithms

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

```
public static Set<String> getSupportedAlgorithms ()
```

Returns supported IPsec algorithms for the current device.

Some algorithms may not be supported on old devices. Callers MUST check if an algorithm is
supported before using it.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/util/Set<https://developer.android.com/reference/java/lang/String>` | This value cannot be `null`. <br /> |

### getTruncationLengthBits

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

```
public int getTruncationLengthBits ()
```

Get the truncation length of this algorithm, in bits

<br />

| Returns ||
|---|---|
| `int` | <br /> |

### toString

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

```
public String toString ()
```

Returns a string representation of the object.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/String` | This value cannot be `null`. <br /> |

### writeToParcel

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

```
public void writeToParcel (Parcel out, 
                int flags)
```

Write to parcel

<br />

| Parameters ||
|---|---|
| `out` | `Parcel`: The Parcel in which the object should be written. This value cannot be `null`. <br /> |
| `flags` | `int`: Additional flags about how the object should be written. May be 0 or `https://developer.android.com/reference/android/os/Parcelable#PARCELABLE_WRITE_RETURN_VALUE`. Value is either `0` or a combination of the following: - `https://developer.android.com/reference/android/os/Parcelable#PARCELABLE_WRITE_RETURN_VALUE` |