MongoDB\Driver\ClientEncryption::encrypt

Encrypt a value

&reftitle.description; final public `MongoDB\BSON\Binary` `MongoDB\Driver\ClientEncryption::encrypt` `mixed` `value` ``array``null```options`&null;

Encrypts the value.

&reftitle.parameters;

`value`

- The value to be encrypted. Any value that can be inserted into MongoDB can be encrypted using this method.

&mongodb.parameter.encryptOpts;
&reftitle.returnvalues;

Returns the encrypted value as `MongoDB\BSON\Binary` object with subtype 6.

&reftitle.errors;

&mongodb.throws.argumentparsing;
- Throws `MongoDB\Driver\Exception\EncryptionException` if an error occurs while encrypting the value

&reftitle.changelog;

&Version; | &Description;
PECL mongodb 1.20.0 | Added the `"trimFactor"` range option. The `"sparsity"` range option is now optional.
PECL mongodb 1.16.0 | Added the `"rangeOpts"` option.
PECL mongodb 1.14.0 | Added the `"contentionFactor"` and `"queryType"` options.

&reftitle.seealso;

- `MongoDB\Driver\ClientEncryption::decrypt`
- `MongoDB\Driver\ClientEncryption::encryptExpression`