# Keystore.decrypt

Decrypts a [JSON keystore](https://ethereum.org/en/developers/docs/data-structures-and-encoding/web3-secret-storage/) into a private key.

Supports the following key derivation functions (KDFs): - [`Keystore.pbkdf2`](/api/Keystore/pbkdf2) - [`Keystore.scrypt`](/api/Keystore/scrypt)

## Imports

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

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

## Examples

```ts twoslash
// @noErrors
import { Keystore, Secp256k1 } from 'ox'

// JSON keystore.
const keystore = { crypto: { ... }, id: '...', version: 3 }

// Derive the key using your password.
const key = Keystore.toKey(keystore, { password: 'hunter2' })

// Decrypt the private key.
const privateKey = Keystore.decrypt(keystore, key)
// @log: "0x..."
```

## Definition

```ts
function decrypt<as>(
  keystore: Keystore.Keystore,
  key: Key,
  options?: decrypt.Options<as>,
): decrypt.ReturnType<as>
```

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

## Parameters

### keystore

* **Type:** [`Keystore.Keystore`](/api/Keystore/types#keystorekeystore)

JSON keystore.

#### keystore.cipher

* **Type:** `"aes-128-ctr"`

#### keystore.cipherparams

* **Type:** `{ iv: string; }`

#### keystore.ciphertext

* **Type:** `string`

#### keystore.crypto

* **Type:** `{ cipher: "aes-128-ctr"; ciphertext: string; cipherparams: { iv: string; }; mac: string; } & Pick`

#### keystore.id

* **Type:** `string`

#### keystore.iv

* **Type:** `string`

#### keystore.mac

* **Type:** `string`

#### keystore.version

* **Type:** `3`

### key

* **Type:** [`Key`](/api/Keystore/types#keystorekey)

Key to use for decryption.

### options

* **Type:** `decrypt.Options<as>`
* **Optional**

Decryption options.

#### options.as

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

Output format.

## Return Type

Decrypted private key.

`decrypt.ReturnType<as>`
