<commit_before>.. _zend.crypt.blockcipher:

Encrypt/decrypt using block ciphers
===================================

``Zend\Crypt\BlockCipher`` implements the encrypt-then-authenticate mode using `HMAC`_ to provide authentication.

The symmetric cipher can be choose with a specific adapter that implements the
``Zend\Crypt\Symmetric\SymmetricInterface``. We support the standard algorithms of the `Mcrypt`_ extension. The
adapter that implements the Mcrypt is ``Zend\Crypt\Symmetric\Mcrypt``.

In the following code we reported an example on how to use the BlockCipher class to encrypt-then-authenticate a
string using the `AES`_ block cipher (with a key of 256 bit) and the HMAC algorithm (using the `SHA-256`_ hash
function).

.. code-block:: php
   :linenos:

   use Zend\Crypt\BlockCipher;

   $blockCipher = BlockCipher::factory('mcrypt', array('algo' => 'aes'));
   $blockCipher->setKey('encryption key');
   $result = $blockCipher->encrypt('this is a secret message');
   echo "Encrypted text: $result \n";
<commit_msg>Typo fix, choose -> chosen.<commit_after>.. _zend.crypt.blockcipher:

Encrypt/decrypt using block ciphers
===================================

``Zend\Crypt\BlockCipher`` implements the encrypt-then-authenticate mode using `HMAC`_ to provide authentication.

The symmetric cipher can be chosen with a specific adapter that implements the
``Zend\Crypt\Symmetric\SymmetricInterface``. We support the standard algorithms of the `Mcrypt`_ extension. The
adapter that implements the Mcrypt is ``Zend\Crypt\Symmetric\Mcrypt``.

In the following code we reported an example on how to use the BlockCipher class to encrypt-then-authenticate a
string using the `AES`_ block cipher (with a key of 256 bit) and the HMAC algorithm (using the `SHA-256`_ hash
function).

.. code-block:: php
   :linenos:

   use Zend\Crypt\BlockCipher;

   $blockCipher = BlockCipher::factory('mcrypt', array('algo' => 'aes'));
   $blockCipher->setKey('encryption key');
   $result = $blockCipher->encrypt('this is a secret message');
   echo "Encrypted text: $result \n";

{'fraction_non_alphanumeric': 0.13539651837524178, 'fraction_numerical': 0.005802707930367505, 'mean_word_length': 4.9971014492753625, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '672223', 'n_tokens_mistral': 637, 'n_tokens_neox': 586, 'n_words': 219}