Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 310 and 401] [Versions 311 and 401] [Versions 39 and 401] [Versions 400 and 401]

   1  <?php
   2  /**
   3   * Copyright 2012-2017 Horde LLC (http://www.horde.org/)
   4   *
   5   * See the enclosed file LICENSE for license information (LGPL). If you
   6   * did not receive this file, see http://www.horde.org/licenses/lgpl21.
   7   *
   8   * @author   Michael Slusarz <slusarz@horde.org>
   9   * @category Horde
  10   * @license  http://www.horde.org/licenses/lgpl21 LGPL 2.1
  11   * @package  Crypt_Blowfish
  12   */
  13  
  14  /**
  15   * Openssl driver for blowfish encryption.
  16   *
  17   * @author    Michael Slusarz <slusarz@horde.org>
  18   * @category  Horde
  19   * @copyright 2012-2017 Horde LLC
  20   * @license   http://www.horde.org/licenses/lgpl21 LGPL 2.1
  21   * @package   Crypt_Blowfish
  22   */
  23  class Horde_Crypt_Blowfish_Openssl extends Horde_Crypt_Blowfish_Base
  24  {
  25      /**
  26       */
  27      public static function supported()
  28      {
  29          if (extension_loaded('openssl')) {
  30              $ciphers = openssl_get_cipher_methods();
  31              return  in_array('bf-ecb', $ciphers) && in_array('bf-cbc', $ciphers);
  32          }
  33  
  34          return false;
  35      }
  36  
  37      /**
  38       */
  39      public function encrypt($text)
  40      {
  41          if (PHP_VERSION_ID <= 50302) {
  42              return @openssl_encrypt($text, 'bf-' . $this->cipher, $this->key, true);
  43          } elseif (PHP_VERSION_ID == 50303) {
  44              // Need to mask error output, since an invalid warning message was
  45              // issued prior to 5.3.4 for empty IVs in ECB mode.
  46              return @openssl_encrypt($text, 'bf-' . $this->cipher, $this->key, true, strval($this->iv));
  47          }
  48  
  49          return openssl_encrypt($text, 'bf-' . $this->cipher, $this->key, true, strval($this->iv));
  50      }
  51  
  52      /**
  53       */
  54      public function decrypt($text)
  55      {
  56          return (PHP_VERSION_ID <= 50302)
  57              ? openssl_decrypt($text, 'bf-' . $this->cipher, $this->key, true)
  58              : openssl_decrypt($text, 'bf-' . $this->cipher, $this->key, true, strval($this->iv));
  59      }
  60  
  61  }