---
name: "mongoc_client_encryption_encrypt"
section: "3"
platform: "linux"
package: "libmongoc-doc"
version: "1.30.4-1+deb13u3"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/mongoc_client_encryption_encrypt"
---

# mongoc\_client\_encryption\_encrypt(3)

## SYNOPSIS

```
bool
mongoc_client_encryption_encrypt (
   mongoc_client_encryption_t *client_encryption,
   const bson_value_t *value,
   mongoc_client_encryption_encrypt_opts_t *opts,
   bson_value_t *ciphertext,
   bson_error_t *error);
```

Performs explicit encryption.

**ciphertext** is always initialized (even on failure). Caller must call *bson\_value\_destroy()* to free.

To insert or query with an "Indexed" or "Range" encrypted payload, use a *mongoc\_client\_t* configured with *mongoc\_auto\_encryption\_opts\_t*. The *mongoc\_auto\_encryption\_opts\_t* may be configured to bypass query analysis with *mongoc\_auto\_encryption\_opts\_set\_bypass\_query\_analysis()*. The *mongoc\_auto\_encryption\_opts\_t* must not be configured to bypass automatic encryption with *mongoc\_auto\_encryption\_opts\_set\_bypass\_auto\_encryption()*.

To insert with a **Range** payload *mongoc\_client\_encryption\_encrypt\_range\_opts\_t* must be set in **opts**.

To query with a **Range** payload, use *mongoc\_client\_encryption\_encrypt\_expression()*

## PARAMETERS

- •

  **client\_encryption**: A *mongoc\_client\_encryption\_t*

- •

  **value**: The value to encrypt.

- •

  **opts**: A *mongoc\_client\_encryption\_encrypt\_opts\_t*.

- •

  **ciphertext**: A *bson\_value\_t* for the resulting ciphertext (a BSON binary with subtype 6).

- •

  **error**: A *bson\_error\_t* set on failure.

## RETURNS

Returns **true** if successful. Returns **false** and sets **error** otherwise.

**SEE ALSO:**

```
mongoc_client_encryption_encrypt_opts_t
```

```
mongoc_client_enable_auto_encryption()
```

```
mongoc_client_decryption_decrypt()
```

```
mongoc_client_encryption_encrypt_expression()
```

## AUTHOR

MongoDB, Inc

## COPYRIGHT

2009-present, MongoDB, Inc.
