# P256.getSharedSecret

Computes a shared secret using ECDH (Elliptic Curve Diffie-Hellman) between a private key and a public key.

## Imports

:::code-group
```ts [Named]
import { P256 } from 'ox'
```

```ts [Entrypoint]
import * as P256 from 'ox/P256'
```
:::

## Examples

```ts twoslash
import { P256 } from 'ox'

const { privateKey: privateKeyA } = P256.createKeyPair()
const { publicKey: publicKeyB } = P256.createKeyPair()

const sharedSecret = P256.getSharedSecret({
  privateKey: privateKeyA,
  publicKey: publicKeyB
})
```

## Definition

```ts
function getSharedSecret<as>(
  options: getSharedSecret.Options<as>,
): getSharedSecret.ReturnType<as>
```

**Source:** [src/core/P256.ts](https://github.com/wevm/ox/blob/main/src/core/P256.ts#L416)

## Parameters

### options

* **Type:** `getSharedSecret.Options<as>`

The options to compute the shared secret.

#### options.as

* **Type:** `"Bytes" | "Hex" | as`
* **Optional**

Format of the returned shared secret.

#### options.privateKey

* **Type:** `0x${string} | Uint8Array`

Private key to use for the shared secret computation.

#### options.publicKey

* **Type:** `0x${string} | Uint8Array | { prefix: number; x: 0x${string}; y: 0x${string}; } | { prefix: number; x: 0x${string}; y?: undefined; }`

Public key to use for the shared secret computation.

Accepts a structured [`PublicKey.PublicKey`](/api/PublicKey/types#publickey), a serialized hex
string, or a `Uint8Array` (SEC1 encoding).

## Return Type

The computed shared secret.

`getSharedSecret.ReturnType<as>`
