Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.0.x will end 8 May 2023 (12 months).
  • Bug fixes for security issues in 4.0.x will end 13 November 2023 (18 months).
  • PHP version: minimum PHP 7.3.0 Note: the minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is also supported.
   1  <?php
   2  /**
   3   * Copyright 2005-2008 Matthew Fonda <mfonda@php.net>
   4   * Copyright 2008 Philippe Jausions <jausions@php.net>
   5   * Copyright 2012-2017 Horde LLC (http://www.horde.org/)
   6   *
   7   * See the enclosed file LICENSE for license information (LGPL). If you
   8   * did not receive this file, see http://www.horde.org/licenses/lgpl21.
   9   *
  10   * @author   Matthew Fonda <mfonda@php.net>
  11   * @author   Philippe Jausions <jausions@php.net>
  12   * @author   Michael Slusarz <slusarz@horde.org>
  13   * @category Horde
  14   * @license  http://www.horde.org/licenses/lgpl21 LGPL 2.1
  15   * @package  Crypt_Blowfish
  16   */
  17  
  18  /**
  19   * Native PHP driver for blowfish encryption.
  20   *
  21   * @author    Matthew Fonda <mfonda@php.net>
  22   * @author    Philippe Jausions <jausions@php.net>
  23   * @author    Michael Slusarz <slusarz@horde.org>
  24   * @category  Horde
  25   * @copyright 2005-2008 Matthew Fonda
  26   * @copyright 2008 Philippe Jausions
  27   * @copyright 2012-2017 Horde LLC
  28   * @license   http://www.horde.org/licenses/lgpl21 LGPL 2.1
  29   * @package   Crypt_Blowfish
  30   */
  31  class Horde_Crypt_Blowfish_Php extends Horde_Crypt_Blowfish_Base
  32  {
  33      /**
  34       * Subclass object.
  35       *
  36       * @var Horde_Crypt_Blowfish_Php_Base
  37       */
  38      protected $_ob;
  39  
  40      /**
  41       */
  42      public function encrypt($text)
  43      {
  44          $this->_init();
  45          return $this->_ob->encrypt($this->_pad($text), $this->iv);
  46      }
  47  
  48      /**
  49       */
  50      public function decrypt($text)
  51      {
  52          $this->_init();
  53          return $this->_unpad($this->_ob->decrypt($this->_pad($text, true), $this->iv));
  54      }
  55  
  56      /**
  57       * Initialize the subclass.
  58       */
  59      protected function _init()
  60      {
  61          if (!isset($this->_ob) ||
  62              ($this->_ob->md5 != hash('md5', $this->key))) {
  63              switch ($this->cipher) {
  64              case 'cbc':
  65                  $this->_ob = new Horde_Crypt_Blowfish_Php_Cbc($this->key);
  66                  break;
  67  
  68              case 'ecb':
  69                  $this->_ob = new Horde_Crypt_Blowfish_Php_Ecb($this->key);
  70                  break;
  71              }
  72          }
  73      }
  74  
  75  }