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

# IpSecTransform.Builder

*** ** * ** ***

` public static class IpSecTransform.Builder `   
` extends https://developer.android.com/reference/java/lang/Object ` ` `

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

<br />

*** ** * ** ***

This class is used to build `https://developer.android.com/reference/android/net/IpSecTransform` objects.

## Summary

| ### Public constructors ||
|---|---|
| ` https://developer.android.com/reference/android/net/IpSecTransform.Builder#Builder(android.content.Context)(https://developer.android.com/reference/android/content/Context context) ` Create a new IpSecTransform.Builder. |

| ### Public methods ||
|---|---|
| ` https://developer.android.com/reference/android/net/IpSecTransform` | ` https://developer.android.com/reference/android/net/IpSecTransform.Builder#buildTransportModeTransform(java.net.InetAddress,%20android.net.IpSecManager.SecurityParameterIndex)(https://developer.android.com/reference/java/net/InetAddress sourceAddress, https://developer.android.com/reference/android/net/IpSecManager.SecurityParameterIndex spi) ` Build a transport mode `https://developer.android.com/reference/android/net/IpSecTransform`. |
| ` https://developer.android.com/reference/android/net/IpSecTransform.Builder` | ` https://developer.android.com/reference/android/net/IpSecTransform.Builder#setAuthenticatedEncryption(android.net.IpSecAlgorithm)(https://developer.android.com/reference/android/net/IpSecAlgorithm algo) ` Set the authenticated encryption algorithm. |
| ` https://developer.android.com/reference/android/net/IpSecTransform.Builder` | ` https://developer.android.com/reference/android/net/IpSecTransform.Builder#setAuthentication(android.net.IpSecAlgorithm)(https://developer.android.com/reference/android/net/IpSecAlgorithm algo) ` Set the authentication (integrity) algorithm. |
| ` https://developer.android.com/reference/android/net/IpSecTransform.Builder` | ` https://developer.android.com/reference/android/net/IpSecTransform.Builder#setEncryption(android.net.IpSecAlgorithm)(https://developer.android.com/reference/android/net/IpSecAlgorithm algo) ` Set the encryption algorithm. |
| ` https://developer.android.com/reference/android/net/IpSecTransform.Builder` | ` https://developer.android.com/reference/android/net/IpSecTransform.Builder#setIpv4Encapsulation(android.net.IpSecManager.UdpEncapsulationSocket,%20int)(https://developer.android.com/reference/android/net/IpSecManager.UdpEncapsulationSocket localSocket, int remotePort) ` Add UDP encapsulation to an IPv4 transform. |

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

## Public constructors

### Builder

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

```
public Builder (Context context)
```

Create a new IpSecTransform.Builder.

<br />

| Parameters ||
|---|---|
| `context` | `Context`: current context. This value cannot be `null`. <br /> |

## Public methods

### buildTransportModeTransform

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

```
public IpSecTransform buildTransportModeTransform (InetAddress sourceAddress, 
                IpSecManager.SecurityParameterIndex spi)
```

Build a transport mode `https://developer.android.com/reference/android/net/IpSecTransform`.

This builds and activates a transport mode transform. Note that an active transform will not affect any network traffic until it has been applied to one or more sockets.

<br />

| Parameters ||
|---|---|
| `sourceAddress` | `InetAddress`: the source `InetAddress` of traffic on sockets that will use this transform; this address must belong to the Network used by all sockets that utilize this transform; if provided, then only traffic originating from the specified source address will be processed. This value cannot be `null`. <br /> |
| `spi` | `IpSecManager.SecurityParameterIndex`: a unique `https://developer.android.com/reference/android/net/IpSecManager.SecurityParameterIndex` to identify transformed traffic. This value cannot be `null`. <br /> |

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

| Throws ||
|---|---|
| `https://developer.android.com/reference/android/net/IpSecManager.ResourceUnavailableException` | indicating that too many transforms are active |
| `https://developer.android.com/reference/android/net/IpSecManager.SpiUnavailableException` | indicating the rare case where an SPI collides with an existing transform |
| `https://developer.android.com/reference/java/io/IOException` | indicating other errors |
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | indicating that a particular combination of transform properties is invalid |

**See also:**

- `https://developer.android.com/reference/android/net/IpSecManager#applyTransportModeTransform(java.io.FileDescriptor,%20int,%20android.net.IpSecTransform)`

### setAuthenticatedEncryption

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

```
public IpSecTransform.Builder setAuthenticatedEncryption (IpSecAlgorithm algo)
```

Set the authenticated encryption algorithm.

The Authenticated Encryption (AE) class of algorithms are also known as Authenticated Encryption with Associated Data (AEAD) algorithms, or Combined mode algorithms (as referred to in [RFC 4301](https://tools.ietf.org/html/rfc4301)).

Authenticated encryption is mutually exclusive with encryption and authentication.

<br />

| Parameters ||
|---|---|
| `algo` | `IpSecAlgorithm`: `https://developer.android.com/reference/android/net/IpSecAlgorithm` specifying the authenticated encryption algorithm to be applied. This value cannot be `null`. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/net/IpSecTransform.Builder` | This value cannot be `null`. <br /> |

### setAuthentication

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

```
public IpSecTransform.Builder setAuthentication (IpSecAlgorithm algo)
```

Set the authentication (integrity) algorithm.

Authentication is mutually exclusive with authenticated encryption.

<br />

| Parameters ||
|---|---|
| `algo` | `IpSecAlgorithm`: `https://developer.android.com/reference/android/net/IpSecAlgorithm` specifying the authentication to be applied. This value cannot be `null`. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/net/IpSecTransform.Builder` | This value cannot be `null`. <br /> |

### setEncryption

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

```
public IpSecTransform.Builder setEncryption (IpSecAlgorithm algo)
```

Set the encryption algorithm.

Encryption is mutually exclusive with authenticated encryption.

<br />

| Parameters ||
|---|---|
| `algo` | `IpSecAlgorithm`: `https://developer.android.com/reference/android/net/IpSecAlgorithm` specifying the encryption to be applied. This value cannot be `null`. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/net/IpSecTransform.Builder` | This value cannot be `null`. <br /> |

### setIpv4Encapsulation

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

```
public IpSecTransform.Builder setIpv4Encapsulation (IpSecManager.UdpEncapsulationSocket localSocket, 
                int remotePort)
```

Add UDP encapsulation to an IPv4 transform.

This allows IPsec traffic to pass through a NAT.

<br />

| Parameters ||
|---|---|
| `localSocket` | `IpSecManager.UdpEncapsulationSocket`: a socket for sending and receiving encapsulated traffic. This value cannot be `null`. <br /> |
| `remotePort` | `int`: the UDP port number of the remote host that will send and receive encapsulated traffic. In the case of IKEv2, this should be port 4500. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/net/IpSecTransform.Builder` | This value cannot be `null`. <br /> |

**See also:**

- [RFC 3948, UDP Encapsulation of IPsec ESP Packets](https://tools.ietf.org/html/rfc3948)
- [RFC 7296 section 2.23, NAT Traversal of IKEv2](https://tools.ietf.org/html/rfc7296#section-2.23)