---
title: encapsulate()
framework: cryptokit
role: symbol
role_heading: Instance Method
path: cryptokit/kempublickey/encapsulate()
---

# encapsulate()

Generates and encapsulates a shared secret.

## Declaration

```swift
func encapsulate() throws -> KEM.EncapsulationResult
```

## Return Value

Return Value The shared secret, and its encapsulated version.

## Discussion

Discussion Share the encapsulated secret with the person who has the KEMPrivateKey. They use decapsulate(_:) to recover the shared secret.
