CI_Encryption::_mcrypt_initialize PHP Méthode

_mcrypt_initialize() protected méthode

Initialize MCrypt
protected _mcrypt_initialize ( array $params ) : void
$params array Configuration parameters
Résultat void
    protected function _mcrypt_initialize($params)
    {
        if (!empty($params['cipher'])) {
            $params['cipher'] = strtolower($params['cipher']);
            $this->_cipher_alias($params['cipher']);
            if (!in_array($params['cipher'], mcrypt_list_algorithms(), TRUE)) {
                log_message('error', 'Encryption: MCrypt cipher ' . strtoupper($params['cipher']) . ' is not available.');
            } else {
                $this->_cipher = $params['cipher'];
            }
        }
        if (!empty($params['mode'])) {
            $params['mode'] = strtolower($params['mode']);
            if (!isset($this->_modes['mcrypt'][$params['mode']])) {
                log_message('error', 'Encryption: MCrypt mode ' . strtoupper($params['mode']) . ' is not available.');
            } else {
                $this->_mode = $this->_modes['mcrypt'][$params['mode']];
            }
        }
        if (isset($this->_cipher, $this->_mode)) {
            if (is_resource($this->_handle) && (strtolower(mcrypt_enc_get_algorithms_name($this->_handle)) !== $this->_cipher or strtolower(mcrypt_enc_get_modes_name($this->_handle)) !== $this->_mode)) {
                mcrypt_module_close($this->_handle);
            }
            if ($this->_handle = mcrypt_module_open($this->_cipher, '', $this->_mode, '')) {
                log_message('info', 'Encryption: MCrypt cipher ' . strtoupper($this->_cipher) . ' initialized in ' . strtoupper($this->_mode) . ' mode.');
            } else {
                log_message('error', 'Encryption: Unable to initialize MCrypt with cipher ' . strtoupper($this->_cipher) . ' in ' . strtoupper($this->_mode) . ' mode.');
            }
        }
    }