# IpSecTransform.Builder

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

# Builder

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/android/net/IpSecTransform.Builder "View this page in Java")  

```
class Builder
```

|---|--------------------------------------------------------------------------------------------------------------------------|
| [kotlin.Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)                                           ||
| ↳ | [android.net.IpSecTransform.Builder](https://developer.android.com/reference/kotlin/android/net/IpSecTransform.Builder#) |

This class is used to build[IpSecTransform](https://developer.android.com/reference/kotlin/android/net/IpSecTransform)objects.

## Summary

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

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

## Public constructors

### Builder

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

```
Builder(context: Context)
```

Create a new IpSecTransform.Builder.

|                                                                   Parameters                                                                   ||
|-----------|-------------------------------------------------------------------------------------------------------------------------------------|
| `context` | [Context](https://developer.android.com/reference/kotlin/android/content/Context.html#):current context This value cannot be`null`. |

## Public methods

### buildTransportModeTransform

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

```
open fun buildTransportModeTransform(
    sourceAddress: InetAddress, 
    spi: IpSecManager.SecurityParameterIndex
): IpSecTransform
```

Build a transport mode[IpSecTransform](https://developer.android.com/reference/kotlin/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.

|                                                                                                                                                                                                Parameters                                                                                                                                                                                                 ||
|-----------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `sourceAddress` | [InetAddress](https://developer.android.com/reference/kotlin/java/net/InetAddress.html#):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`. |
| `spi`           | [IpSecManager.SecurityParameterIndex](https://developer.android.com/reference/kotlin/android/net/IpSecManager.SecurityParameterIndex):a unique[IpSecManager.SecurityParameterIndex](https://developer.android.com/reference/kotlin/android/net/IpSecManager.SecurityParameterIndex)to identify transformed traffic This value cannot be`null`.                                           |

|                                                          Return                                                          ||
|---------------------------------------------------------------------------------------------|-----------------------------|
| [IpSecTransform](https://developer.android.com/reference/kotlin/android/net/IpSecTransform) | This value cannot be`null`. |

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

**See Also**

### setAuthenticatedEncryption

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

```
open fun setAuthenticatedEncryption(algo: IpSecAlgorithm): IpSecTransform.Builder
```

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.

|                                                                                                                                         Parameters                                                                                                                                          ||
|--------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `algo` | [IpSecAlgorithm](https://developer.android.com/reference/kotlin/android/net/IpSecAlgorithm):[IpSecAlgorithm](https://developer.android.com/reference/kotlin/android/net/IpSecAlgorithm)specifying the authenticated encryption algorithm to be applied. This value cannot be`null`. |

|                                                                  Return                                                                   ||
|--------------------------------------------------------------------------------------------------------------|-----------------------------|
| [IpSecTransform.Builder](https://developer.android.com/reference/kotlin/android/net/IpSecTransform.Builder#) | This value cannot be`null`. |

### setAuthentication

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

```
open fun setAuthentication(algo: IpSecAlgorithm): IpSecTransform.Builder
```

Set the authentication (integrity) algorithm.

Authentication is mutually exclusive with authenticated encryption.

|                                                                                                                               Parameters                                                                                                                                ||
|--------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `algo` | [IpSecAlgorithm](https://developer.android.com/reference/kotlin/android/net/IpSecAlgorithm):[IpSecAlgorithm](https://developer.android.com/reference/kotlin/android/net/IpSecAlgorithm)specifying the authentication to be applied. This value cannot be`null`. |

|                                                                  Return                                                                   ||
|--------------------------------------------------------------------------------------------------------------|-----------------------------|
| [IpSecTransform.Builder](https://developer.android.com/reference/kotlin/android/net/IpSecTransform.Builder#) | This value cannot be`null`. |

### setEncryption

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

```
open fun setEncryption(algo: IpSecAlgorithm): IpSecTransform.Builder
```

Set the encryption algorithm.

Encryption is mutually exclusive with authenticated encryption.

|                                                                                                                             Parameters                                                                                                                              ||
|--------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `algo` | [IpSecAlgorithm](https://developer.android.com/reference/kotlin/android/net/IpSecAlgorithm):[IpSecAlgorithm](https://developer.android.com/reference/kotlin/android/net/IpSecAlgorithm)specifying the encryption to be applied. This value cannot be`null`. |

|                                                                  Return                                                                   ||
|--------------------------------------------------------------------------------------------------------------|-----------------------------|
| [IpSecTransform.Builder](https://developer.android.com/reference/kotlin/android/net/IpSecTransform.Builder#) | This value cannot be`null`. |

### setIpv4Encapsulation

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

```
open fun setIpv4Encapsulation(
    localSocket: IpSecManager.UdpEncapsulationSocket, 
    remotePort: Int
): IpSecTransform.Builder
```

Add UDP encapsulation to an IPv4 transform.

This allows IPsec traffic to pass through a NAT.

|                                                                                                                Parameters                                                                                                                ||
|---------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `localSocket` | [IpSecManager.UdpEncapsulationSocket](https://developer.android.com/reference/kotlin/android/net/IpSecManager.UdpEncapsulationSocket):a socket for sending and receiving encapsulated traffic This value cannot be`null`. |
| `remotePort`  | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html):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.        |

|                                                                  Return                                                                   ||
|--------------------------------------------------------------------------------------------------------------|-----------------------------|
| [IpSecTransform.Builder](https://developer.android.com/reference/kotlin/android/net/IpSecTransform.Builder#) | This value cannot be`null`. |

**See Also**