<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/class.mongodb-driver-clientencryption.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'en',
  ),
  'this' => 
  array (
    0 => 'mongodb-driver-clientencryption.createdatakey.php',
    1 => 'MongoDB\\Driver\\ClientEncryption::createDataKey',
    2 => 'Creates a key document',
  ),
  'up' => 
  array (
    0 => 'class.mongodb-driver-clientencryption.php',
    1 => 'MongoDB\\Driver\\ClientEncryption',
  ),
  'prev' => 
  array (
    0 => 'mongodb-driver-clientencryption.construct.php',
    1 => 'MongoDB\\Driver\\ClientEncryption::__construct',
  ),
  'next' => 
  array (
    0 => 'mongodb-driver-clientencryption.decrypt.php',
    1 => 'MongoDB\\Driver\\ClientEncryption::decrypt',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/mongodb/mongodb/driver/clientencryption/createdatakey.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="mongodb-driver-clientencryption.createdatakey" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">MongoDB\Driver\ClientEncryption::createDataKey</h1>
  <p class="verinfo">(mongodb &gt;=1.7.0)</p><p class="refpurpose"><span class="refname">MongoDB\Driver\ClientEncryption::createDataKey</span> &mdash; <span class="dc-title">Creates a key document</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-mongodb-driver-clientencryption.createdatakey-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">final</span> <span class="modifier">public</span> <span class="methodname"><strong>MongoDB\Driver\ClientEncryption::createDataKey</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$kmsProvider</code></span>, <span class="methodparam"><span class="type"><span class="type"><a href="language.types.null.php" class="type null">?</a></span><span class="type"><a href="language.types.array.php" class="type array">array</a></span></span> <code class="parameter">$options</code><span class="initializer"> = <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong></span></span>): <span class="type"><a href="class.mongodb-bson-binary.php" class="type MongoDB\BSON\Binary">MongoDB\BSON\Binary</a></span></div>

  <p class="para rdfs-comment">
   Creates a new key document and inserts it into the key vault collection.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-mongodb-driver-clientencryption.createdatakey-parameters">
  <h3 class="title">Parameters</h3>
  <dl>
   
    <dt><code class="parameter">kmsProvider</code></dt>
    <dd>
     <p class="para">
      The KMS provider (e.g. <code class="literal">&quot;local&quot;</code>,
      <code class="literal">&quot;aws&quot;</code>) that will be used to encrypt the new data key.
     </p>
    </dd>
   

   
    <dt><code class="parameter">options</code></dt>
    <dd>
     <p class="para">
      <table class="doctable table">
       <caption><strong>Data key options</strong></caption>
       
        <thead>
         <tr>
          <th>Option</th>
          <th>Type</th>
          <th>Description</th>
         </tr>

        </thead>

        <tbody class="tbody">
         <tr>
          <td>masterKey</td>
          <td><span class="type"><a href="language.types.array.php" class="type array">array</a></span></td>
          <td>
           <p class="para">
            The masterKey document identifies a KMS-specific key used to encrypt
            the new data key. This option is required unless
            <code class="parameter">kmsProvider</code> is <code class="literal">&quot;local&quot;</code>.
           </p>
           
  <p class="para">
   <table class="doctable table">
    <caption><strong><code class="literal">&quot;aws&quot;</code> provider options</strong></caption>
    
     <thead>
      <tr>
       <th>Option</th>
       <th>Type</th>
       <th>Description</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>region</td>
       <td>string</td>
       <td>Required.</td>
      </tr>

      <tr>
       <td>key</td>
       <td>string</td>
       <td>Required. The Amazon Resource Name (ARN) to the AWS customer master key (CMK).</td>
      </tr>

      <tr>
       <td>endpoint</td>
       <td>string</td>
       <td>Optional. An alternate host identifier to send KMS requests to. May include port number.</td>
      </tr>

     </tbody>
    
   </table>

  </p>
  <p class="para">
   <table class="doctable table">
    <caption><strong><code class="literal">&quot;azure&quot;</code> provider options</strong></caption>
    
     <thead>
      <tr>
       <th>Option</th>
       <th>Type</th>
       <th>Description</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>keyVaultEndpoint</td>
       <td>string</td>
       <td>Required. Host with optional port (e.g. &quot;example.vault.azure.net&quot;).</td>
      </tr>

      <tr>
       <td>keyName</td>
       <td>string</td>
       <td>Required.</td>
      </tr>

      <tr>
       <td>keyVersion</td>
       <td>string</td>
       <td>Optional. A specific version of the named key. Defaults to using the key&#039;s primary version.</td>
      </tr>

     </tbody>
    
   </table>

  </p>
  <p class="para">
   <table class="doctable table">
    <caption><strong><code class="literal">&quot;gcp&quot;</code> provider options</strong></caption>
    
     <thead>
      <tr>
       <th>Option</th>
       <th>Type</th>
       <th>Description</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>projectId</td>
       <td>string</td>
       <td>Required.</td>
      </tr>

      <tr>
       <td>location</td>
       <td>string</td>
       <td>Required.</td>
      </tr>

      <tr>
       <td>keyRing</td>
       <td>string</td>
       <td>Required.</td>
      </tr>

      <tr>
       <td>keyName</td>
       <td>string</td>
       <td>Required.</td>
      </tr>

      <tr>
       <td>keyVersion</td>
       <td>string</td>
       <td>Optional. A specific version of the named key. Defaults to using the key&#039;s primary version.</td>
      </tr>

      <tr>
       <td>endpoint</td>
       <td>string</td>
       <td>Optional. Host with optional port. Defaults to &quot;cloudkms.googleapis.com&quot;.</td>
      </tr>

     </tbody>
    
   </table>

  </p>
  <p class="para">
   <table class="doctable table">
    <caption><strong><code class="literal">&quot;kmip&quot;</code> provider options</strong></caption>
    
     <thead>
      <tr>
       <th>Option</th>
       <th>Type</th>
       <th>Description</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>keyId</td>
       <td>string</td>
       <td>Optional. Unique identifier to a 96-byte KMIP secret data managed object. If unspecified, the driver creates a random 96-byte KMIP secret data managed object.</td>
      </tr>

      <tr>
       <td>endpoint</td>
       <td>string</td>
       <td>Optional. Host with optional port.</td>
      </tr>

      <tr>
       <td>delegated</td>
       <td>bool</td>
       <td>Optional. If true, this key should be decrypted by the KMIP server.</td>
      </tr>

     </tbody>
    
   </table>

  </p>

          </td>
         </tr>

         <tr>
          <td>keyAltNames</td>
          <td><span class="type"><a href="language.types.array.php" class="type array">array</a></span></td>
          <td>
           <p class="para">
            An optional list of string alternate names used to reference a key.
            If a key is created with alternate names, then encryption may refer
            to the key by the unique alternate name instead of by
            <code class="literal">_id</code>.
           </p>
          </td>
         </tr>

         <tr>
          <td>keyMaterial</td>
          <td><span class="classname"><a href="class.mongodb-bson-binary.php" class="classname">MongoDB\BSON\Binary</a></span></td>
          <td>
           <p class="para">
            An optional 96-byte value to use as custom key material for the data
            key being created. If keyMaterial is given, the custom key material
            is used for encrypting and decrypting data. Otherwise, the key
            material for the new data key is generated from a cryptographically
            secure random device.
           </p>
          </td>
         </tr>

        </tbody>
       
      </table>

     </p>
    </dd>
   
  </dl>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-mongodb-driver-clientencryption.createdatakey-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
   Returns the identifier of the new key as a
   <span class="classname"><a href="class.mongodb-bson-binary.php" class="classname">MongoDB\BSON\Binary</a></span> object with subtype 4 (UUID).
  </p>
 </div>


 <div class="refsect1 errors" id="refsect1-mongodb-driver-clientencryption.createdatakey-errors">
  <h3 class="title">Errors/Exceptions</h3>
  <ul class="simplelist">
   <li>Throws <span class="classname"><a href="class.mongodb-driver-exception-invalidargumentexception.php" class="classname">MongoDB\Driver\Exception\InvalidArgumentException</a></span> on argument parsing errors.</li><li>Throws <span class="classname"><a href="class.mongodb-driver-exception-connectionexception.php" class="classname">MongoDB\Driver\Exception\ConnectionException</a></span> if connection to the server fails (for reasons other than authentication).</li><li>Throws <span class="classname"><a href="class.mongodb-driver-exception-authenticationexception.php" class="classname">MongoDB\Driver\Exception\AuthenticationException</a></span> if authentication is needed and fails.</li>
   <li>Throws <span class="classname"><a href="class.mongodb-driver-exception-runtimeexception.php" class="classname">MongoDB\Driver\Exception\RuntimeException</a></span> on other errors.</li>
  </ul>
 </div>


 <div class="refsect1 changelog" id="refsect1-mongodb-driver-clientencryption.createdatakey-changelog">
  <h3 class="title">Changelog</h3>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>Version</th>
       <th>Description</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>PECL mongodb 1.20.0</td>
       <td>
        Added <code class="literal">&quot;delegated&quot;</code> to the KMIP provider masterKey options.
       </td>
      </tr>

      <tr>
       <td>PECL mongodb 1.15.0</td>
       <td>
        Added the <code class="literal">&quot;keyMaterial&quot;</code> option.
       </td>
      </tr>

      <tr>
       <td>PECL mongodb 1.10.0</td>
       <td>
        Azure and GCP are now supported as KMS providers for client-side
        encryption.
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>


</div><?php manual_footer($setup); ?>