[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/libraries/src/Encrypt/AES/ -> AesInterface.php (source)

   1  <?php
   2  
   3  /**
   4   * Joomla! Content Management System
   5   *
   6   * @copyright  (C) 2016 Open Source Matters, Inc. <https://www.joomla.org>
   7   * @license    GNU General Public License version 2 or later; see LICENSE.txt
   8   */
   9  
  10  namespace Joomla\CMS\Encrypt\AES;
  11  
  12  // phpcs:disable PSR1.Files.SideEffects
  13  \defined('JPATH_PLATFORM') or die;
  14  // phpcs:enable PSR1.Files.SideEffects
  15  
  16  /**
  17   * Interface for AES encryption adapters
  18   *
  19   * @since    4.0.0
  20   */
  21  interface AesInterface
  22  {
  23      /**
  24       * Sets the AES encryption mode.
  25       *
  26       * WARNING: The strength is deprecated as it has a different effect in MCrypt and OpenSSL. MCrypt was abandoned in
  27       * 2003 before the Rijndael-128 algorithm was officially the Advanced Encryption Standard (AES). MCrypt also offered
  28       * Rijndael-192 and Rijndael-256 algorithms with different block sizes. These are NOT used in AES. OpenSSL, however,
  29       * implements AES correctly. It always uses a 128-bit (16 byte) block. The 192 and 256 bit strengths refer to the
  30       * key size, not the block size. Therefore using different strengths in MCrypt and OpenSSL will result in different
  31       * and incompatible ciphertexts.
  32       *
  33       * TL;DR: Always use $strength = 128!
  34       *
  35       * @param   string  $mode      Choose between CBC (recommended) or ECB
  36       * @param   int     $strength  Bit strength of the key (128, 192 or 256 bits). DEPRECATED. READ NOTES ABOVE.
  37       *
  38       * @return  mixed
  39       */
  40      public function setEncryptionMode($mode = 'cbc', $strength = 128);
  41  
  42      /**
  43       * Encrypts a string. Returns the raw binary ciphertext.
  44       *
  45       * WARNING: The plaintext is zero-padded to the algorithm's block size. You are advised to store the size of the
  46       * plaintext and trim the string to that length upon decryption.
  47       *
  48       * @param   string       $plainText  The plaintext to encrypt
  49       * @param   string       $key        The raw binary key (will be zero-padded or chopped if its size is different than the block size)
  50       * @param   null|string  $iv         The initialization vector (for CBC mode algorithms)
  51       *
  52       * @return  string  The raw encrypted binary string.
  53       */
  54      public function encrypt($plainText, $key, $iv = null);
  55  
  56      /**
  57       * Decrypts a string. Returns the raw binary plaintext.
  58       *
  59       * $ciphertext MUST start with the IV followed by the ciphertext, even for EBC data (the first block of data is
  60       * dropped in EBC mode since there is no concept of IV in EBC).
  61       *
  62       * WARNING: The returned plaintext is zero-padded to the algorithm's block size during encryption. You are advised
  63       * to trim the string to the original plaintext's length upon decryption. While rtrim($decrypted, "\0") sounds
  64       * appealing it's NOT the correct approach for binary data (zero bytes may actually be part of your plaintext, not
  65       * just padding!).
  66       *
  67       * @param   string  $cipherText  The ciphertext to encrypt
  68       * @param   string  $key         The raw binary key (will be zero-padded or chopped if its size is different than the block size)
  69       *
  70       * @return  string  The raw unencrypted binary string.
  71       */
  72      public function decrypt($cipherText, $key);
  73  
  74      /**
  75       * Returns the encryption block size in bytes
  76       *
  77       * @return  integer
  78       */
  79      public function getBlockSize();
  80  
  81      /**
  82       * Is this adapter supported?
  83       *
  84       * @return  boolean
  85       */
  86      public function isSupported();
  87  }


Generated: Wed Sep 7 05:41:13 2022 Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer