> ## Documentation Index
> Fetch the complete documentation index at: https://infisical.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Encrypt data

> Encrypt data with a KMS key from the Node.js SDK.

`client.kms().encryption().encrypt()` encrypts data with an encryption key in a [KMS](https://infisical.com/docs/documentation/platform/kms/overview.md) project.

## Parameters

**options** `KmsEncryptDataOptions` *required*

**properties**

**keyId** `string` *required*

The ID of an encryption key.

**plaintext** `string` *required*

The data to encrypt, encoded in base64.

## Returns

**ciphertext** `string`

The encrypted data, which [`decrypt`](https://infisical.com/docs/sdks/languages/node/kms/decrypt) takes.

```typescript Basic theme={"dark"}
const ciphertext = await client.kms().encryption().encrypt({
  keyId: "<key-id>",
  plaintext: Buffer.from("4242 4242 4242 4242").toString("base64"),
});
```

```json Response theme={"dark"}
"vnHhD3Lr7tYx0Q2Jm8hZbW5pK1cRf4sNq9aUeO6gT3yVdXlB0iEwCjM7zPkHuGs"
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.