Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 3.9.x will end* 10 May 2021 (12 months).
  • Bug fixes for security issues in 3.9.x will end* 8 May 2023 (36 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

Differences Between: [Versions 39 and 401] [Versions 39 and 402] [Versions 39 and 403]

   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          return extension_loaded('openssl');
  30      }
  31  
  32      /**
  33       */
  34      public function encrypt($text)
  35      {
  36          if (PHP_VERSION_ID <= 50302) {
  37              return @openssl_encrypt($text, 'bf-' . $this->cipher, $this->key, true);
  38          } elseif (PHP_VERSION_ID == 50303) {
  39              // Need to mask error output, since an invalid warning message was
  40              // issued prior to 5.3.4 for empty IVs in ECB mode.
  41              return @openssl_encrypt($text, 'bf-' . $this->cipher, $this->key, true, strval($this->iv));
  42          }
  43  
  44          return openssl_encrypt($text, 'bf-' . $this->cipher, $this->key, true, strval($this->iv));
  45      }
  46  
  47      /**
  48       */
  49      public function decrypt($text)
  50      {
  51          return (PHP_VERSION_ID <= 50302)
  52              ? openssl_decrypt($text, 'bf-' . $this->cipher, $this->key, true)
  53              : openssl_decrypt($text, 'bf-' . $this->cipher, $this->key, true, strval($this->iv));
  54      }
  55  
  56  }