<section>
 <h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
  KeyVault.createKey()
  <a class="headerlink leafygreen-ui-1kepx47" href="#keyvault.createkey--" title="Permalink to this heading">
   <svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
    <path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
    </path>
    <path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
    </path>
   </svg>
   <div class="css-1btu0w3 evvkmar0" id="keyvault.createkey--">
   </div>
  </a>
 </h1>
 <div class="leafygreen-ui-a5yxub">
  <p class="css-1cmx2d4 ef7gu8j0">
   On this page
  </p>
  <ul class="css-1qb0mst ef7gu8j1">
   <li class="leafygreen-ui-1e7a0ei">
    <a class="lg-ui-0001 leafygreen-ui-e98ikf" href="#behavior" target="_self">
     <span>
      Behavior
     </span>
    </a>
   </li>
   <li class="leafygreen-ui-1jqtqlb">
    <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#example" target="_self">
     <span>
      Example
     </span>
    </a>
   </li>
  </ul>
 </div>
 <dl class="method">
  <dt>
   <code class="leafygreen-ui-1l06pbn">
    KeyVault.createKey(keyManagementService, customerMasterKey, ["keyAltName"])
   </code>
   <a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-method-KeyVault.createKey" title="Permalink to this definition">
    <svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
     <path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
     </path>
     <path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
     </path>
    </svg>
    <div class="css-1btu0w3 evvkmar0" id="mongodb-method-KeyVault.createKey">
    </div>
   </a>
  </dt>
  <dd>
   <p class="leafygreen-ui-1kp3ins">
    Adds a data encryption key to the key vault associated to the
database connection.
    <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/csfle/#std-label-manual-csfle-feature">
     Client-Side Field Level Encryption
    </a>
    uses data encryption keys for supporting
encryption and decryption of field values.
   </p>
   <p class="leafygreen-ui-1kp3ins">
    <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-KeyVault.createKey" target="_self">
     <span>
      <code class="leafygreen-ui-1l06pbn">
       createKey()
      </code>
     </span>
    </a>
    has the following syntax:
   </p>
   <script class="structured_data" type="application/ld+json">
    {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"keyVault = db.getMongo().getKeyVault()\n\nkeyVault.createKey(\n  keyManagementService,\n  customerMasterKey,\n  [ \"keyAltName\" ]\n)","programmingLanguage":"JavaScript"}
   </script>
   <div class="css-16lmvu9">
    <div class="leafygreen-ui-196mwvg">
     <div class="leafygreen-ui-yzcs8i">
      <pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">keyVault <!-- -->= <!-- -->db.<span class="lg-highlight-title lg-highlight-function">getMongo</span>(<!-- -->).<span class="lg-highlight-title lg-highlight-function">getKeyVault</span>(<!-- -->)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><div class="leafygreen-ui-ihxujy"></div></td></tr><tr class=""><td class="leafygreen-ui-7razhx">keyVault.<span class="lg-highlight-title lg-highlight-function">createKey</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx">  <!-- -->keyManagementService<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">  <!-- -->customerMasterKey<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">  <!-- -->[ <span class="lg-highlight-string">"keyAltName"</span> ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx">)</td></tr></tbody></table></code></pre>
      <div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
       <button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
        <div class="leafygreen-ui-xhlipt">
         <svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
          <path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
          </path>
         </svg>
        </div>
       </button>
      </div>
     </div>
    </div>
   </div>
   <div class="leafygreen-ui-skkc39" tabindex="0">
    <table class="leafygreen-ui-hr8lsv">
     <colgroup>
      <col style="width:20%"/>
      <col style="width:20%"/>
      <col style="width:80%"/>
     </colgroup>
     <thead class="leafygreen-ui-a9ho40">
      <tr data-testid="leafygreen-ui-header-row">
       <th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col">
        <div class="leafygreen-ui-ui0te9">
         <div>
          Parameter
         </div>
        </div>
       </th>
       <th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
        <div class="leafygreen-ui-ui0te9">
         <div>
          Type
         </div>
        </div>
       </th>
       <th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
        <div class="leafygreen-ui-ui0te9">
         <div>
          Description
         </div>
        </div>
       </th>
      </tr>
     </thead>
     <tbody>
      <tr class="">
       <td class="leafygreen-ui-1drjk7h">
        <div class="leafygreen-ui-1n4j8xf">
         <div>
          <code class="leafygreen-ui-1l06pbn">
           keyManagementService
          </code>
         </div>
        </div>
       </td>
       <td class="leafygreen-ui-1drjk7h">
        <div class="leafygreen-ui-1n4j8xf">
         <div>
          string
         </div>
        </div>
       </td>
       <td class="leafygreen-ui-1drjk7h">
        <div class="leafygreen-ui-1n4j8xf">
         <div>
          <p class="leafygreen-ui-1kp3ins">
           <em>
            Required
           </em>
          </p>
          <p class="leafygreen-ui-1kp3ins">
           The
           <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/queryable-encryption/fundamentals/kms-providers/#std-label-qe-fundamentals-kms-providers">
            Key Management Service (KMS)
           </a>
           to use for retrieving the
Customer Master Key (CMK). Accepts the following parameters:
          </p>
          <ul class="leafygreen-ui-rioki0">
           <li class="leafygreen-ui-d7p7b6">
            <p class="leafygreen-ui-1kp3ins">
             <code class="leafygreen-ui-1l06pbn">
              aws
             </code>
             for
             <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/queryable-encryption/fundamentals/kms-providers/#std-label-qe-fundamentals-kms-providers-aws">
              Amazon Web Services KMS
             </a>
             . Requires specifying a
Customer Master Key (CMK) string for
             <code class="leafygreen-ui-1l06pbn">
              customerMasterKey
             </code>
             .
            </p>
           </li>
           <li class="leafygreen-ui-d7p7b6">
            <p class="leafygreen-ui-1kp3ins">
             <code class="leafygreen-ui-1l06pbn">
              azure
             </code>
             for
             <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/queryable-encryption/fundamentals/kms-providers/#std-label-qe-fundamentals-kms-providers-azure">
              Azure Key Vault
             </a>
             . Requires
specifying a Customer Master Key (CMK) document for
             <code class="leafygreen-ui-1l06pbn">
              customerMasterKey
             </code>
             .
            </p>
            <div>
             <p>
              <em>
               New
               <!-- -->
               in version
               <!-- -->
               5.0
              </em>
              .
             </p>
            </div>
           </li>
           <li class="leafygreen-ui-d7p7b6">
            <p class="leafygreen-ui-1kp3ins">
             <code class="leafygreen-ui-1l06pbn">
              gcp
             </code>
             for
             <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/queryable-encryption/fundamentals/kms-providers/#std-label-qe-fundamentals-kms-providers-gcp">
              Google Cloud Platform KMS
             </a>
             . Requires specifying a
Customer Master Key (CMK) document for
             <code class="leafygreen-ui-1l06pbn">
              customerMasterKey
             </code>
             .
            </p>
            <div>
             <p>
              <em>
               New
               <!-- -->
               in version
               <!-- -->
               5.0
              </em>
              .
             </p>
            </div>
           </li>
           <li class="leafygreen-ui-d7p7b6">
            <p class="leafygreen-ui-1kp3ins">
             <code class="leafygreen-ui-1l06pbn">
              local
             </code>
             for a
             <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/queryable-encryption/fundamentals/kms-providers/#std-label-qe-fundamentals-kms-providers-local">
              locally managed key
              <!-- -->
              .
             </a>
            </p>
           </li>
          </ul>
          <p class="leafygreen-ui-1kp3ins">
           If the
           <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/Mongo/#mongodb-method-Mongo">
            <code class="leafygreen-ui-1l06pbn">
             database connection
            </code>
           </a>
           was not
configured with the specified KMS, data encryption key
creation fails.
          </p>
         </div>
        </div>
       </td>
      </tr>
      <tr class="">
       <td class="leafygreen-ui-1drjk7h">
        <div class="leafygreen-ui-1n4j8xf">
         <div>
          <code class="leafygreen-ui-1l06pbn">
           customerMasterKey
          </code>
         </div>
        </div>
       </td>
       <td class="leafygreen-ui-1drjk7h">
        <div class="leafygreen-ui-1n4j8xf">
         <div>
          string or document
         </div>
        </div>
       </td>
       <td class="leafygreen-ui-1drjk7h">
        <div class="leafygreen-ui-1n4j8xf">
         <div>
          <p class="leafygreen-ui-1kp3ins">
           The Customer Master Key (CMK) to use for encrypting the data
encryption key. Required if
           <code class="leafygreen-ui-1l06pbn">
            keyManagementService
           </code>
           is
           <code class="leafygreen-ui-1l06pbn">
            aws
           </code>
           ,
           <code class="leafygreen-ui-1l06pbn">
            azure
           </code>
           , or
           <code class="leafygreen-ui-1l06pbn">
            gcp
           </code>
           .
          </p>
          <p class="leafygreen-ui-1kp3ins">
           Provide the CMK as follows depending on your KMS provider:
          </p>
          <ul class="leafygreen-ui-rioki0">
           <li class="leafygreen-ui-d7p7b6">
            <p class="leafygreen-ui-1kp3ins">
             For the
             <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/queryable-encryption/fundamentals/kms-providers/#std-label-qe-fundamentals-kms-providers-aws">
              Amazon Web Services KMS
             </a>
             , specify the full
             <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html" rel="noopener noreferrer">
              <span>
               Amazon Resource Name (ARN)
              </span>
              <svg alt="" aria-hidden="true" class="leafygreen-ui-1ie5kuq" height="16" role="presentation" viewbox="0 0 16 16" width="16">
               <path d="M13.823 2.4491C13.8201 2.30008 13.6999 2.17994 13.5509 2.17704L9.5062 2.09836C9.25654 2.09351 9.12821 2.39519 9.30482 2.5718L10.3856 3.65257L7.93433 6.10383C7.87964 6.15852 7.83047 6.21665 7.78683 6.27752L5.99909 8.06525C5.46457 8.59977 5.46457 9.4664 5.99909 10.0009C6.53361 10.5354 7.40023 10.5354 7.93475 10.0009L9.72249 8.21317C9.78336 8.16953 9.84148 8.12037 9.89618 8.06567L12.3474 5.61441L13.4282 6.69518C13.6048 6.87179 13.9065 6.74347 13.9016 6.4938L13.823 2.4491Z" fill="currentColor">
               </path>
               <path d="M7.25 3.12893C7.66421 3.12893 8 3.46472 8 3.87893C8 4.29315 7.66421 4.62893 7.25 4.62893H4C3.72386 4.62893 3.5 4.85279 3.5 5.12893V11.9929C3.5 12.2691 3.72386 12.4929 4 12.4929H10.864C11.1401 12.4929 11.364 12.2691 11.364 11.9929V8.75C11.364 8.33579 11.6998 8 12.114 8C12.5282 8 12.864 8.33579 12.864 8.75V11.9929C12.864 13.0975 11.9686 13.9929 10.864 13.9929H4C2.89543 13.9929 2 13.0975 2 11.9929V5.12893C2 4.02436 2.89543 3.12893 4 3.12893H7.25Z" fill="currentColor">
               </path>
              </svg>
             </a>
             of the master key as a single string.
            </p>
           </li>
           <li class="leafygreen-ui-d7p7b6">
            <p class="leafygreen-ui-1kp3ins">
             For the
             <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/queryable-encryption/fundamentals/kms-providers/#std-label-qe-fundamentals-kms-providers-azure">
              Azure Key Vault
             </a>
             KMS, specify a
document containing the following key value pairs:
            </p>
            <ul class="leafygreen-ui-rioki0">
             <li class="leafygreen-ui-d7p7b6">
              <p class="leafygreen-ui-1kp3ins">
               <code class="leafygreen-ui-1l06pbn">
                keyName
               </code>
               - The
               <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://docs.microsoft.com/en-us/azure/key-vault/general/about-keys-secrets-certificates#vault-name-and-object-name" rel="noopener noreferrer">
                <span>
                 Azure Key Vault Name
                </span>
                <svg alt="" aria-hidden="true" class="leafygreen-ui-1ie5kuq" height="16" role="presentation" viewbox="0 0 16 16" width="16">
                 <path d="M13.823 2.4491C13.8201 2.30008 13.6999 2.17994 13.5509 2.17704L9.5062 2.09836C9.25654 2.09351 9.12821 2.39519 9.30482 2.5718L10.3856 3.65257L7.93433 6.10383C7.87964 6.15852 7.83047 6.21665 7.78683 6.27752L5.99909 8.06525C5.46457 8.59977 5.46457 9.4664 5.99909 10.0009C6.53361 10.5354 7.40023 10.5354 7.93475 10.0009L9.72249 8.21317C9.78336 8.16953 9.84148 8.12037 9.89618 8.06567L12.3474 5.61441L13.4282 6.69518C13.6048 6.87179 13.9065 6.74347 13.9016 6.4938L13.823 2.4491Z" fill="currentColor">
                 </path>
                 <path d="M7.25 3.12893C7.66421 3.12893 8 3.46472 8 3.87893C8 4.29315 7.66421 4.62893 7.25 4.62893H4C3.72386 4.62893 3.5 4.85279 3.5 5.12893V11.9929C3.5 12.2691 3.72386 12.4929 4 12.4929H10.864C11.1401 12.4929 11.364 12.2691 11.364 11.9929V8.75C11.364 8.33579 11.6998 8 12.114 8C12.5282 8 12.864 8.33579 12.864 8.75V11.9929C12.864 13.0975 11.9686 13.9929 10.864 13.9929H4C2.89543 13.9929 2 13.0975 2 11.9929V5.12893C2 4.02436 2.89543 3.12893 4 3.12893H7.25Z" fill="currentColor">
                 </path>
                </svg>
               </a>
              </p>
             </li>
             <li class="leafygreen-ui-d7p7b6">
              <p class="leafygreen-ui-1kp3ins">
               <code class="leafygreen-ui-1l06pbn">
                keyVaultEndpoint
               </code>
               - The DNS name of the Azure Key Vault
to use
              </p>
             </li>
             <li class="leafygreen-ui-d7p7b6">
              <p class="leafygreen-ui-1kp3ins">
               <code class="leafygreen-ui-1l06pbn">
                keyVersion
               </code>
               - Optional. The version of the key
specified in
               <code class="leafygreen-ui-1l06pbn">
                keyName
               </code>
               , if applicable
              </p>
             </li>
            </ul>
            <div>
             <p>
              <em>
               New
               <!-- -->
               in version
               <!-- -->
               5.0
              </em>
              .
             </p>
            </div>
           </li>
           <li class="leafygreen-ui-d7p7b6">
            <p class="leafygreen-ui-1kp3ins">
             For the
             <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/queryable-encryption/fundamentals/kms-providers/#std-label-qe-fundamentals-kms-providers-gcp">
              Google Cloud Platform KMS
             </a>
             , specify a
document containing the following key value pairs:
            </p>
            <ul class="leafygreen-ui-rioki0">
             <li class="leafygreen-ui-d7p7b6">
              <p class="leafygreen-ui-1kp3ins">
               <code class="leafygreen-ui-1l06pbn">
                projectId
               </code>
               - The GCP project name
              </p>
             </li>
             <li class="leafygreen-ui-d7p7b6">
              <p class="leafygreen-ui-1kp3ins">
               <code class="leafygreen-ui-1l06pbn">
                location
               </code>
               - The location of the KMS keyring
              </p>
             </li>
             <li class="leafygreen-ui-d7p7b6">
              <p class="leafygreen-ui-1kp3ins">
               <code class="leafygreen-ui-1l06pbn">
                keyRing
               </code>
               - The name of the KMS keyring (often 'global')
              </p>
             </li>
             <li class="leafygreen-ui-d7p7b6">
              <p class="leafygreen-ui-1kp3ins">
               <code class="leafygreen-ui-1l06pbn">
                keyName
               </code>
               - The name of the key to use
              </p>
             </li>
             <li class="leafygreen-ui-d7p7b6">
              <p class="leafygreen-ui-1kp3ins">
               <code class="leafygreen-ui-1l06pbn">
                keyVersion
               </code>
               - Optional. The version of the key
specified in
               <code class="leafygreen-ui-1l06pbn">
                keyName
               </code>
               , if applicable
              </p>
             </li>
            </ul>
            <div>
             <p>
              <em>
               New
               <!-- -->
               in version
               <!-- -->
               5.0
              </em>
              .
             </p>
            </div>
           </li>
          </ul>
          <p class="leafygreen-ui-1kp3ins">
           <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-KeyVault.createKey" target="_self">
            <span>
             <code class="leafygreen-ui-1l06pbn">
              createKey()
             </code>
            </span>
           </a>
           requests
that the KMS encrypt the data encryption key material
using the specified CMK. If the CMK does not exist
           <em>
            or
           </em>
           if the
           <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/Mongo/#std-label-autoEncryptionOpts">
            <code class="leafygreen-ui-1l06pbn">
             AutoEncryptionOpts
            </code>
           </a>
           configuration
does not have sufficient privileges to use the CMK,
           <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-KeyVault.createKey" target="_self">
            <span>
             <code class="leafygreen-ui-1l06pbn">
              createKey()
             </code>
            </span>
           </a>
           returns an error.
          </p>
          <p class="leafygreen-ui-1kp3ins">
           This parameter has no effect if
           <code class="leafygreen-ui-1l06pbn">
            keyManagementService
           </code>
           is
           <code class="leafygreen-ui-1l06pbn">
            local
           </code>
           and can be safely omitted.
          </p>
         </div>
        </div>
       </td>
      </tr>
      <tr class="">
       <td class="leafygreen-ui-1drjk7h">
        <div class="leafygreen-ui-1n4j8xf">
         <div>
          <code class="leafygreen-ui-1l06pbn">
           keyAltName
          </code>
         </div>
        </div>
       </td>
       <td class="leafygreen-ui-1drjk7h">
        <div class="leafygreen-ui-1n4j8xf">
         <div>
          array of strings
         </div>
        </div>
       </td>
       <td class="leafygreen-ui-1drjk7h">
        <div class="leafygreen-ui-1n4j8xf">
         <div>
          <p class="leafygreen-ui-1kp3ins">
           <em>
            Optional
           </em>
          </p>
          <p class="leafygreen-ui-1kp3ins">
           The alternative name for the data encryption key. Use
           <code class="leafygreen-ui-1l06pbn">
            keyAltName
           </code>
           to improve findability of a specific data
encryption key, or as an analog to a comment.
          </p>
          <p class="leafygreen-ui-1kp3ins">
           The
           <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/getKeyVault/#mongodb-method-getKeyVault">
            <code class="leafygreen-ui-1l06pbn">
             getKeyVault()
            </code>
           </a>
           method automatically creates a
           <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/index-unique/#std-label-index-type-unique">
            unique index
           </a>
           on the
           <code class="leafygreen-ui-1l06pbn">
            keyAltNames
           </code>
           field with a
           <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/index-partial/#std-label-index-type-partial">
            partial index
           </a>
           filter for only documents where
           <code class="leafygreen-ui-1l06pbn">
            keyAltNames
           </code>
           exists.
          </p>
         </div>
        </div>
       </td>
      </tr>
      <tr class="">
       <td class="leafygreen-ui-1drjk7h">
        <div class="leafygreen-ui-1n4j8xf">
         <div>
          <code class="leafygreen-ui-1l06pbn">
           options
          </code>
         </div>
        </div>
       </td>
       <td class="leafygreen-ui-1drjk7h">
        <div class="leafygreen-ui-1n4j8xf">
         <div>
          document
         </div>
        </div>
       </td>
       <td class="leafygreen-ui-1drjk7h">
        <div class="leafygreen-ui-1n4j8xf">
         <div>
          <p class="leafygreen-ui-1kp3ins">
           <em>
            Optional
           </em>
          </p>
          <p class="leafygreen-ui-1kp3ins">
           A document that specifies options for the new key.
           <code class="leafygreen-ui-1l06pbn">
            options
           </code>
           has the following fields:
          </p>
          <ul class="leafygreen-ui-rioki0">
           <li class="leafygreen-ui-d7p7b6">
            <p class="leafygreen-ui-1kp3ins">
             <code class="leafygreen-ui-1l06pbn">
              masterKey
             </code>
             : the new master key to encrypt data.
            </p>
           </li>
           <li class="leafygreen-ui-d7p7b6">
            <p class="leafygreen-ui-1kp3ins">
             <code class="leafygreen-ui-1l06pbn">
              keyAltNames
             </code>
             : an array of alternate names, one per
master key.
            </p>
           </li>
           <li class="leafygreen-ui-d7p7b6">
            <p class="leafygreen-ui-1kp3ins">
             <code class="leafygreen-ui-1l06pbn">
              keyMaterial
             </code>
             : bindata used to create the key.
            </p>
           </li>
          </ul>
         </div>
        </div>
       </td>
      </tr>
     </tbody>
    </table>
   </div>
   <table class="css-11h39yh e1nex8bq0">
    <colgroup>
     <col class="field-name"/>
     <col class="field-body"/>
    </colgroup>
    <tbody>
     <tr class="css-x8snli">
      <th>
       Returns
       <!-- -->
       :
      </th>
      <td>
       The
       <code class="leafygreen-ui-1l06pbn">
        UUID
       </code>
       unique identifier of the created data encryption
key.
      </td>
     </tr>
    </tbody>
   </table>
  </dd>
 </dl>
 <section>
  <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
   Behavior
   <a class="headerlink leafygreen-ui-1kepx47" href="#behavior" title="Permalink to this heading">
    <svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
     <path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
     </path>
     <path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
     </path>
    </svg>
    <div class="css-1btu0w3 evvkmar0" id="behavior">
    </div>
   </a>
  </h2>
  <section>
   <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
    Requires Configuring Client-Side Field Level Encryption on Database Connection
    <a class="headerlink leafygreen-ui-1kepx47" href="#requires-configuring-client-side-field-level-encryption-on-database-connection" title="Permalink to this heading">
     <svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
      <path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
      </path>
      <path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
      </path>
     </svg>
     <div class="css-1btu0w3 evvkmar0" id="requires-configuring-client-side-field-level-encryption-on-database-connection">
     </div>
    </a>
   </h3>
   <p class="leafygreen-ui-1kp3ins">
    The
    <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/#mongodb-binary-bin.mongosh" target="_self">
     <span>
      <code class="leafygreen-ui-1l06pbn">
       mongosh
      </code>
     </span>
    </a>
    client-side field level encryption methods
require a database connection with client-side field level encryption
enabled. If the current database connection was not initiated with
client-side field level encryption enabled, either:
   </p>
   <ul class="leafygreen-ui-rioki0">
    <li class="leafygreen-ui-d7p7b6">
     <p class="leafygreen-ui-1kp3ins">
      Use the
      <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/Mongo/#mongodb-method-Mongo">
       <code class="leafygreen-ui-1l06pbn">
        Mongo()
       </code>
      </a>
      constructor from the
      <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/#mongodb-binary-bin.mongosh" target="_self">
       <span>
        <code class="leafygreen-ui-1l06pbn">
         mongosh
        </code>
       </span>
      </a>
      to establish a connection with the required client-side field
level encryption options. The
      <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/Mongo/#mongodb-method-Mongo">
       <code class="leafygreen-ui-1l06pbn">
        Mongo()
       </code>
      </a>
      method supports the
following Key Management Service (KMS) providers for Customer
Master Key (CMK) management:
     </p>
     <ul class="leafygreen-ui-rioki0">
      <li class="leafygreen-ui-d7p7b6">
       <p class="leafygreen-ui-1kp3ins">
        <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/queryable-encryption/fundamentals/kms-providers/#std-label-qe-fundamentals-kms-providers-aws">
         Amazon Web Services KMS
        </a>
       </p>
      </li>
      <li class="leafygreen-ui-d7p7b6">
       <p class="leafygreen-ui-1kp3ins">
        <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/queryable-encryption/fundamentals/kms-providers/#std-label-qe-fundamentals-kms-providers-azure">
         Azure Key Vault
        </a>
       </p>
      </li>
      <li class="leafygreen-ui-d7p7b6">
       <p class="leafygreen-ui-1kp3ins">
        <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/queryable-encryption/fundamentals/kms-providers/#std-label-qe-fundamentals-kms-providers-gcp">
         Google Cloud Platform KMS
        </a>
       </p>
      </li>
      <li class="leafygreen-ui-d7p7b6">
       <p class="leafygreen-ui-1kp3ins">
        <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/queryable-encryption/fundamentals/kms-providers/#std-label-qe-fundamentals-kms-providers-local">
         Locally Managed Key
        </a>
       </p>
      </li>
     </ul>
     <p class="leafygreen-ui-1kp3ins">
      <em>
       or
      </em>
     </p>
    </li>
    <li class="leafygreen-ui-d7p7b6">
     <p class="leafygreen-ui-1kp3ins">
      Use the
      <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/#mongodb-binary-bin.mongosh" target="_self">
       <span>
        <code class="leafygreen-ui-1l06pbn">
         mongosh
        </code>
       </span>
      </a>
      <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/reference/options/#std-label-mongosh-client-side-field-level-encryption-options" target="_self">
       <span>
        command line options
       </span>
      </a>
      to establish a
connection with the required options. The command line options only
support the
      <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/queryable-encryption/fundamentals/kms-providers/#std-label-qe-fundamentals-kms-providers-aws">
       Amazon Web Services KMS
      </a>
      provider for CMK management.
     </p>
    </li>
   </ul>
  </section>
 </section>
 <section>
  <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
   Example
   <a class="headerlink leafygreen-ui-1kepx47" href="#example" title="Permalink to this heading">
    <svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
     <path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
     </path>
     <path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
     </path>
    </svg>
    <div class="css-1btu0w3 evvkmar0" id="example">
    </div>
   </a>
  </h2>
  <p class="leafygreen-ui-1kp3ins">
   The following example is intended for rapid evaluation of
client-side field level encryption. For specific examples of using
   <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-KeyVault.createKey" target="_self">
    <span>
     <code class="leafygreen-ui-1l06pbn">
      KeyVault.createKey()
     </code>
    </span>
   </a>
   with each supported
   <span class="leafygreen-ui-vm4wms" tabindex="0">
    KMS
   </span>
   provider, see
   <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/queryable-encryption/quick-start/#std-label-qe-field-level-encryption-data-key-create">
    Create a Data Key
    <!-- -->
    .
   </a>
  </p>
  <script class="structured_data" type="application/ld+json">
   {"@context":"https://schema.org","@type":"HowTo","steps":[{"@type":"HowToStep","text":"Start the mongosh client.","name":"Start mongosh"},{"@type":"HowToStep","text":"To configure client-side field level encryption for a locally\nmanaged key, generate a base64-encoded 96-byte string with no line\nbreaks.","name":"Generate Your Key"},{"@type":"HowToStep","text":"Create the client-side field level encryption options using the\ngenerated local key string:","name":"Create the Client-Side Field Level Encryption Options"},{"@type":"HowToStep","text":"Use the Mongo() constructor with the client-side field level\nencryption options configured to create a database connection. Replace\nthe mongodb://myMongo.example.net URI with the connection\nstring URI of the target cluster.","name":"Create Your Encrypted Client"}],"name":"Example","image":"https://webimages.mongodb.com/_com_assets/cms/kuyj2focmkbxv7gh3-stacked_default_slate_blue.svg?auto=format%252Ccompress"}
  </script>
  <div class="css-4nyere eccljxs0">
   <div class="css-1nuklj8 e1ckbxcu1">
    <div class="css-18fui5z e1ckbxcu0">
     <div class="css-19lsqsq e1ckbxcu2">
      1
     </div>
    </div>
    <div class="css-1ed38mk">
     <section>
      <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
       Start mongosh
       <a class="headerlink leafygreen-ui-1kepx47" href="#start-mongosh" title="Permalink to this heading">
        <svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
         <path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
         </path>
         <path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
         </path>
        </svg>
        <div class="css-1btu0w3 evvkmar0" id="start-mongosh">
        </div>
       </a>
      </h3>
      <p class="leafygreen-ui-1kp3ins">
       Start the
       <code class="leafygreen-ui-1l06pbn">
        mongosh
       </code>
       client.
      </p>
      <script class="structured_data" type="application/ld+json">
       {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"mongosh --nodb","programmingLanguage":"Bash"}
      </script>
      <div class="css-16lmvu9">
       <div class="leafygreen-ui-196mwvg">
        <div class="leafygreen-ui-yzcs8i">
         <pre class="leafygreen-ui-1q4bxgx" tabindex="-1"><code class="lg-highlight-hljs-light bash leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">mongosh --nodb</td></tr></tbody></table></code></pre>
         <div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
          <button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
           <div class="leafygreen-ui-xhlipt">
            <svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
             <path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
             </path>
            </svg>
           </div>
          </button>
         </div>
        </div>
       </div>
      </div>
     </section>
    </div>
   </div>
   <div class="css-1nuklj8 e1ckbxcu1">
    <div class="css-18fui5z e1ckbxcu0">
     <div class="css-19lsqsq e1ckbxcu2">
      2
     </div>
    </div>
    <div class="css-1ed38mk">
     <section>
      <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
       Generate Your Key
       <a class="headerlink leafygreen-ui-1kepx47" href="#generate-your-key" title="Permalink to this heading">
        <svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
         <path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
         </path>
         <path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
         </path>
        </svg>
        <div class="css-1btu0w3 evvkmar0" id="generate-your-key">
        </div>
       </a>
      </h3>
      <p class="leafygreen-ui-1kp3ins">
       To configure client-side field level encryption for a locally
managed key, generate a base64-encoded 96-byte string with no line
breaks.
      </p>
      <script class="structured_data" type="application/ld+json">
       {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"const TEST_LOCAL_KEY = require(\"crypto\").randomBytes(96).toString(\"base64\")","programmingLanguage":"JavaScript"}
      </script>
      <div class="css-16lmvu9">
       <div class="leafygreen-ui-196mwvg">
        <div class="leafygreen-ui-1b1bvay">
         <pre class="leafygreen-ui-1q4bxgx" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">const</span> <span class="lg-highlight-variable lg-highlight-constant">TEST_LOCAL_KEY</span> <!-- -->= <span class="lg-highlight-built_in">require</span>(<span class="lg-highlight-string">"crypto"</span>).<span class="lg-highlight-title lg-highlight-function">randomBytes</span>(<span class="lg-highlight-number">96</span>).<span class="lg-highlight-title lg-highlight-function">toString</span>(<span class="lg-highlight-string">"base64"</span>)</td></tr></tbody></table></code></pre>
         <div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
          <button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
           <div class="leafygreen-ui-xhlipt">
            <svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
             <path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
             </path>
            </svg>
           </div>
          </button>
         </div>
        </div>
       </div>
      </div>
     </section>
    </div>
   </div>
   <div class="css-1nuklj8 e1ckbxcu1">
    <div class="css-18fui5z e1ckbxcu0">
     <div class="css-19lsqsq e1ckbxcu2">
      3
     </div>
    </div>
    <div class="css-1ed38mk">
     <section>
      <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
       Create the Client-Side Field Level Encryption Options
       <a class="headerlink leafygreen-ui-1kepx47" href="#create-the-client-side-field-level-encryption-options" title="Permalink to this heading">
        <svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
         <path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
         </path>
         <path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
         </path>
        </svg>
        <div class="css-1btu0w3 evvkmar0" id="create-the-client-side-field-level-encryption-options">
        </div>
       </a>
      </h3>
      <p class="leafygreen-ui-1kp3ins">
       Create the client-side field level encryption options using the
generated local key string:
      </p>
      <script class="structured_data" type="application/ld+json">
       {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":" var autoEncryptionOpts = {\n   \"keyVaultNamespace\" : \"encryption.__dataKeys\",\n   \"kmsProviders\" : {\n     \"local\" : {\n       \"key\" : BinData(0, TEST_LOCAL_KEY)\n     }\n   }\n }","programmingLanguage":"JavaScript"}
      </script>
      <div class="css-16lmvu9">
       <div class="leafygreen-ui-196mwvg">
        <div class="leafygreen-ui-yzcs8i">
         <pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-keyword">var</span> autoEncryptionOpts <!-- -->= <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   <span class="lg-highlight-string">"keyVaultNamespace"</span> <!-- -->: <span class="lg-highlight-string">"encryption.__dataKeys"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   <span class="lg-highlight-string">"kmsProviders"</span> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx">     <span class="lg-highlight-string">"local"</span> <!-- -->: <!-- -->{</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx">       <span class="lg-highlight-string">"key"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">BinData</span>(<span class="lg-highlight-number">0</span>, <span class="lg-highlight-variable lg-highlight-constant">TEST_LOCAL_KEY</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx">     }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr></tbody></table></code></pre>
         <div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
          <button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
           <div class="leafygreen-ui-xhlipt">
            <svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
             <path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
             </path>
            </svg>
           </div>
          </button>
         </div>
        </div>
       </div>
      </div>
     </section>
    </div>
   </div>
   <div class="css-1nuklj8 e1ckbxcu1">
    <div class="css-18fui5z e1ckbxcu0">
     <div class="css-19lsqsq e1ckbxcu2">
      4
     </div>
    </div>
    <div class="css-1ed38mk">
     <section>
      <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
       Create Your Encrypted Client
       <a class="headerlink leafygreen-ui-1kepx47" href="#create-your-encrypted-client" title="Permalink to this heading">
        <svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
         <path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
         </path>
         <path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
         </path>
        </svg>
        <div class="css-1btu0w3 evvkmar0" id="create-your-encrypted-client">
        </div>
       </a>
      </h3>
      <p class="leafygreen-ui-1kp3ins">
       Use the
       <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/Mongo/#mongodb-method-Mongo">
        <code class="leafygreen-ui-1l06pbn">
         Mongo()
        </code>
       </a>
       constructor with the client-side field level
encryption options configured to create a database connection. Replace
the
       <code class="leafygreen-ui-1l06pbn">
        mongodb://myMongo.example.net
       </code>
       URI with the
       <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/connection-string/#std-label-mongodb-uri">
        connection
string URI
       </a>
       of the target cluster.
      </p>
      <script class="structured_data" type="application/ld+json">
       {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"encryptedClient = Mongo(\n  \"mongodb://myMongo.example.net:27017/?replSetName=myMongo\",\n   autoEncryptionOpts\n)","programmingLanguage":"JavaScript"}
      </script>
      <div class="css-16lmvu9">
       <div class="leafygreen-ui-196mwvg">
        <div class="leafygreen-ui-1b1bvay">
         <pre class="leafygreen-ui-11itue3" tabindex="0"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">encryptedClient <!-- -->= <span class="lg-highlight-title lg-highlight-class">Mongo</span>(</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx">  <span class="lg-highlight-string">"mongodb://myMongo.example.net:27017/?replSetName=myMongo"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">   <!-- -->autoEncryptionOpts</td></tr><tr class=""><td class="leafygreen-ui-7razhx">)</td></tr></tbody></table></code></pre>
         <div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
          <button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
           <div class="leafygreen-ui-xhlipt">
            <svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
             <path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
             </path>
            </svg>
           </div>
          </button>
         </div>
        </div>
       </div>
      </div>
     </section>
    </div>
   </div>
  </div>
  <p class="leafygreen-ui-1kp3ins">
   Retrieve the
   <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/getKeyVault/#mongodb-method-getKeyVault">
    <code class="leafygreen-ui-1l06pbn">
     keyVault
    </code>
   </a>
   object and
use the
   <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-KeyVault.createKey" target="_self">
    <span>
     <code class="leafygreen-ui-1l06pbn">
      KeyVault.createKey()
     </code>
    </span>
   </a>
   method to
create a new data encryption key using the locally managed key:
  </p>
  <script class="structured_data" type="application/ld+json">
   {"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"keyVault = encryptedClient.getKeyVault()\nkeyVault.createKey(\"local\", [\"data-encryption-key\"])","programmingLanguage":"JavaScript"}
  </script>
  <div class="css-16lmvu9">
   <div class="leafygreen-ui-196mwvg">
    <div class="leafygreen-ui-yzcs8i">
     <pre class="leafygreen-ui-11itue3" tabindex="-1"><code class="lg-highlight-hljs-light javascript leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx">keyVault <!-- -->= <!-- -->encryptedClient.<span class="lg-highlight-title lg-highlight-function">getKeyVault</span>(<!-- -->)</td></tr><tr class=""><td class="leafygreen-ui-7razhx">keyVault.<span class="lg-highlight-title lg-highlight-function">createKey</span>(<span class="lg-highlight-string">"local"</span>, <!-- -->[<span class="lg-highlight-string">"data-encryption-key"</span>])</td></tr></tbody></table></code></pre>
     <div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
      <button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
       <div class="leafygreen-ui-xhlipt">
        <svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
         <path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.2857 15H8.71429C7.76751 15 7 14.2325 7 13.2857V12Z" fill="currentColor" fill-rule="evenodd">
         </path>
        </svg>
       </div>
      </button>
     </div>
    </div>
   </div>
  </div>
  <p class="leafygreen-ui-1kp3ins">
   If successful,
   <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-KeyVault.createKey" target="_self">
    <span>
     <code class="leafygreen-ui-1l06pbn">
      createKey()
     </code>
    </span>
   </a>
   returns the
   <code class="leafygreen-ui-1l06pbn">
    UUID
   </code>
   of
the new data encryption key. To retrieve the new data encryption
key document from the key vault, either:
  </p>
  <ul class="leafygreen-ui-rioki0">
   <li class="leafygreen-ui-d7p7b6">
    <p class="leafygreen-ui-1kp3ins">
     Use
     <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/KeyVault.getKey/#mongodb-method-KeyVault.getKey">
      <code class="leafygreen-ui-1l06pbn">
       getKey()
      </code>
     </a>
     to retrieve the created key by
     <code class="leafygreen-ui-1l06pbn">
      UUID
     </code>
     .
    </p>
    <p class="leafygreen-ui-1kp3ins">
     <em>
      -or-
     </em>
    </p>
   </li>
   <li class="leafygreen-ui-d7p7b6">
    <p class="leafygreen-ui-1kp3ins">
     Use
     <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/KeyVault.getKeyByAltName/#mongodb-method-KeyVault.getKeyByAltName">
      <code class="leafygreen-ui-1l06pbn">
       getKeyByAltName()
      </code>
     </a>
     to retrieve the key by its
alternate name.
    </p>
   </li>
  </ul>
 </section>
</section>
