<?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 => 'ru',
  ),
  'this' => 
  array (
    0 => 'mongodb-driver-clientencryption.encrypt.php',
    1 => 'MongoDB\\Driver\\ClientEncryption::encrypt',
    2 => 'Шифрует данные',
  ),
  'up' => 
  array (
    0 => 'class.mongodb-driver-clientencryption.php',
    1 => 'MongoDB\\Driver\\ClientEncryption',
  ),
  'prev' => 
  array (
    0 => 'mongodb-driver-clientencryption.deletekey.php',
    1 => 'MongoDB\\Driver\\ClientEncryption::deleteKey',
  ),
  'next' => 
  array (
    0 => 'mongodb-driver-clientencryption.encryptexpression.php',
    1 => 'MongoDB\\Driver\\ClientEncryption::encryptExpression',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'ru',
    'path' => 'reference/mongodb/mongodb/driver/clientencryption/encrypt.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="mongodb-driver-clientencryption.encrypt" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">MongoDB\Driver\ClientEncryption::encrypt</h1>
  <p class="verinfo">(mongodb &gt;=1.7.0)</p><p class="refpurpose"><span class="refname">MongoDB\Driver\ClientEncryption::encrypt</span> &mdash; <span class="dc-title">Шифрует данные</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-mongodb-driver-clientencryption.encrypt-description">
  <h3 class="title">Описание</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">final</span> <span class="modifier">public</span> <span class="methodname"><strong>MongoDB\Driver\ClientEncryption::encrypt</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.mixed.php" class="type mixed">mixed</a></span> <code class="parameter">$value</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">
   Метод шифрует данные.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-mongodb-driver-clientencryption.encrypt-parameters">
  <h3 class="title">Список параметров</h3>
  <dl>
   
    <dt><code class="parameter">value</code></dt>
    <dd>
     <p class="para">
      Значение для шифрования. Метод шифрует любые значения,
      которые вставляются в БД MongoDB.
     </p>
    </dd>
   

   
   
    <dt><code class="parameter">options</code></dt>
    <dd>
     <p class="para">
      <table class="doctable table">
       <caption><strong>Encryption options</strong></caption>
       
        <thead>
         <tr>
          <th>Опция</th>
          <th>Тип</th>
          <th>Описание</th>
         </tr>

        </thead>

        <tbody class="tbody">
         <tr>
          <td>algorithm</td>
          <td><span class="type"><a href="language.types.string.php" class="type string">string</a></span></td>
          <td>
           <p class="para">
            Алгоритм шифрования, который будет использоваться. Опция обязательна.
            Укажите одну из следующих
            <a href="class.mongodb-driver-clientencryption.php#mongodb-driver-clientencryption.constants" class="link">констант ClientEncryption</a>:
           </p>
           <ul class="simplelist">
            <li><strong><code>MongoDB\Driver\ClientEncryption::AEAD_AES_256_CBC_HMAC_SHA_512_DETERMINISTIC</code></strong></li>
            <li><strong><code>MongoDB\Driver\ClientEncryption::AEAD_AES_256_CBC_HMAC_SHA_512_RANDOM</code></strong></li>
            <li><strong><code><a href="class.mongodb-driver-clientencryption.php#mongodb-driver-clientencryption.constants.algorithm-indexed">MongoDB\Driver\ClientEncryption::ALGORITHM_INDEXED</a></code></strong></li>
            <li><strong><code><a href="class.mongodb-driver-clientencryption.php#mongodb-driver-clientencryption.constants.algorithm-unindexed">MongoDB\Driver\ClientEncryption::ALGORITHM_UNINDEXED</a></code></strong></li>
            <li><strong><code><a href="class.mongodb-driver-clientencryption.php#mongodb-driver-clientencryption.constants.algorithm-range">MongoDB\Driver\ClientEncryption::ALGORITHM_RANGE</a></code></strong></li>
           </ul>
          </td>
         </tr>

         <tr>
          <td>contentionFactor</td>
          <td><span class="type"><a href="language.types.integer.php" class="type int">int</a></span></td>
          <td>
           <p class="para">
            Коэффициент конкуренции для оценки запросов с индексированными
            зашифрованными полезными нагрузками.
           </p>
           <p class="para">
            Опция применяется и может быть указана только тогда, когда
            опция <code class="literal">algorithm</code> равна
            <strong><code><a href="class.mongodb-driver-clientencryption.php#mongodb-driver-clientencryption.constants.algorithm-indexed">MongoDB\Driver\ClientEncryption::ALGORITHM_INDEXED</a></code></strong>
            или
            <strong><code><a href="class.mongodb-driver-clientencryption.php#mongodb-driver-clientencryption.constants.algorithm-range">MongoDB\Driver\ClientEncryption::ALGORITHM_RANGE</a></code></strong>.
           </p>
          </td>
         </tr>

         <tr>
          <td>keyAltName</td>
          <td><span class="type"><a href="language.types.string.php" class="type string">string</a></span></td>
          <td>
           <p class="para">
            Идентифицирует документ коллекции хранилища ключей по <code class="literal">keyAltName</code>.
            Опция является взаимоисключающей с <code class="literal">keyId</code> и требуется ровно один.
           </p>
          </td>
         </tr>

         <tr>
          <td>keyId</td>
          <td><span class="classname"><a href="class.mongodb-bson-binary.php" class="classname">MongoDB\BSON\Binary</a></span></td>
          <td>
           <p class="para">
            Идентифицирует ключ данных по <code class="literal">_id</code>. Значением является UUID
            (двоичный подтип 4). Опция является взаимоисключающей с <code class="literal">keyAltName</code>
            и требуется ровно один.
           </p>
          </td>
         </tr>

         <tr>
          <td>queryType</td>
          <td><span class="type"><a href="language.types.string.php" class="type string">string</a></span></td>
          <td>
           <p class="para">
            Тип запроса для оценки запросов с индексированными, зашифрованными
            полезными нагрузками. Укажите одну из следующих
            <a href="class.mongodb-driver-clientencryption.php#mongodb-driver-clientencryption.constants" class="link">констант ClientEncryption</a>:
           </p>
           <ul class="simplelist">
            <li><strong><code><a href="class.mongodb-driver-clientencryption.php#mongodb-driver-clientencryption.constants.query-type-equality">MongoDB\Driver\ClientEncryption::QUERY_TYPE_EQUALITY</a></code></strong></li>
            <li><strong><code><a href="class.mongodb-driver-clientencryption.php#mongodb-driver-clientencryption.constants.query-type-range">MongoDB\Driver\ClientEncryption::QUERY_TYPE_RANGE</a></code></strong></li>
           </ul>
           <p class="para">
            Опция применяется и может быть указана только тогда, когда
            опция <code class="literal">algorithm</code> равна
            <strong><code><a href="class.mongodb-driver-clientencryption.php#mongodb-driver-clientencryption.constants.algorithm-indexed">MongoDB\Driver\ClientEncryption::ALGORITHM_INDEXED</a></code></strong>
            или <strong><code><a href="class.mongodb-driver-clientencryption.php#mongodb-driver-clientencryption.constants.algorithm-range">MongoDB\Driver\ClientEncryption::ALGORITHM_RANGE</a></code></strong>.
           </p>
          </td>
         </tr>

         <tr>
          <td>rangeOpts</td>
          <td><span class="type"><a href="language.types.array.php" class="type array">array</a></span></td>
          <td>
           <p class="para">
            Опции индекса для шифруемого поля с поддержкой запросов «range».
            Параметры, которые приводят следующие абзацы, должны соответствовать значениям, которые установили
            в параметре <code class="literal">encryptedFields</code> целевой коллекции.
            Для BSON-полей с типом double и decimal128 требуется либо установить все опции
            <code class="literal">min</code>, <code class="literal">max</code> и <code class="literal">precision</code>, либо все отключить.
           </p>
           <p class="para">
            <table class="doctable table">
             <caption><strong>Опции индекса диапазона</strong></caption>
             
              <thead>
               <tr>
                <th>Опция</th>
                <th>Тип</th>
                <th>Описание</th>
               </tr>

              </thead>

              <tbody class="tbody">
               <tr>
                <td>min</td>
                <td><span class="type"><a href="language.types.mixed.php" class="type mixed">mixed</a></span></td>
                <td>
                 Обязательна, если опцию <code class="literal">precision</code> установили. Минимальное
                 BSON-значение в диапазоне.
                </td>
               </tr>

               <tr>
                <td>max</td>
                <td><span class="type"><a href="language.types.mixed.php" class="type mixed">mixed</a></span></td>
                <td>
                 Обязательна, если опцию <code class="literal">precision</code> установили. Максимальное
                 BSON-значение в диапазоне.
                </td>
               </tr>

               <tr>
                <td>sparsity</td>
                <td><span class="type"><a href="language.types.integer.php" class="type int">int</a></span></td>
                <td>Необязательна. Опция принимает положительное 64-битное целое число.</td>
               </tr>

               <tr>
                <td>precision</td>
                <td><span class="type"><a href="language.types.integer.php" class="type int">int</a></span></td>
                <td>
                 Небязательна. Опция принимает положительное 32-битное целое число, которое указывает точность
                 для явного шифрования. Опцию устанавливают только для BSON-полей с типом double
                 или decimal128.
                </td>
               </tr>

               <tr>
                <td>trimFactor</td>
                <td><span class="type"><a href="language.types.integer.php" class="type int">int</a></span></td>
                <td>Необязательна. Положительное 32-битное целое число.</td>
               </tr>

              </tbody>
             
            </table>

           </p>
          </td>
         </tr>

        </tbody>
       
      </table>

     </p>
    </dd>
   

  </dl>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-mongodb-driver-clientencryption.encrypt-returnvalues">
  <h3 class="title">Возвращаемые значения</h3>
  <p class="para">
   Метод возвращает зашифрованные данные в виде объекта
   <span class="classname"><a href="class.mongodb-bson-binary.php" class="classname">MongoDB\BSON\Binary</a></span> с подтипом 6.
  </p>
 </div>


 <div class="refsect1 errors" id="refsect1-mongodb-driver-clientencryption.encrypt-errors">
  <h3 class="title">Ошибки</h3>
  <ul class="simplelist">
   <li>При ошибке парсинга аргумента метод выбрасывает исключение  <span class="classname"><a href="class.mongodb-driver-exception-invalidargumentexception.php" class="classname">MongoDB\Driver\Exception\InvalidArgumentException</a></span>.</li>
   <li>
    Метод выбрасывает исключение <span class="classname"><a href="class.mongodb-driver-exception-encryptionexception.php" class="classname">MongoDB\Driver\Exception\EncryptionException</a></span>,
    если при шифровании возникла ошибка.
   </li>
  </ul>
 </div>


 <div class="refsect1 changelog" id="refsect1-mongodb-driver-clientencryption.encrypt-changelog">
  <h3 class="title">Список изменений</h3>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>Версия</th>
       <th>Описание</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>PECL-модуль mongodb 1.20.0</td>
       <td>
        В список опций параметра шифрования rangeOpts добавили опцию
        индекса диапазона <code class="literal">&quot;trimFactor&quot;</code>. Опция диапазона
        <code class="literal">&quot;sparsity&quot;</code> теперь необязательна.
       </td>
      </tr>

      <tr>
       <td>PECL-модуль mongodb 1.16.0</td>
       <td>
        В список параметров шифрования добавили параметр <code class="literal">&quot;rangeOpts&quot;</code>.
       </td>
      </tr>

      <tr>
       <td>PECL-модуль mongodb 1.14.0</td>
       <td>
        В список параметров шифрования добавили параметры
        <code class="literal">&quot;contentionFactor&quot;</code> и <code class="literal">&quot;queryType&quot;</code>.
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-mongodb-driver-clientencryption.encrypt-seealso">
  <h3 class="title">Смотрите также</h3>
  <ul class="simplelist">
   <li><span class="function"><a href="mongodb-driver-clientencryption.decrypt.php" class="function" rel="rdfs-seeAlso">MongoDB\Driver\ClientEncryption::decrypt()</a> - Расшифровывает данные</span></li>
   <li><span class="function"><a href="mongodb-driver-clientencryption.encryptexpression.php" class="function" rel="rdfs-seeAlso">MongoDB\Driver\ClientEncryption::encryptExpression()</a> - Шифрует совпадение или агрегированное выражение</span></li>
  </ul>
 </div>


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