public function encrypt($data)
    {
        $this->cwsDebug->titleH2('Encrypt data');

        if (empty($this->encryptionKey)) {
            $this->error = 'You have to set the encryption key...';
            $this->cwsDebug->error($this->error);

            return;
        }

        if (empty($data)) {
            $this->error = 'Data empty...';
            $this->cwsDebug->error($this->error);

            return;
        }

        $this->cwsDebug->labelValue('Encryption key', $this->encryptionKey);
        $this->cwsDebug->dump('Data', $data);

        $td = mcrypt_module_open(MCRYPT_BLOWFISH, '', MCRYPT_MODE_CFB, '');

        $ivsize = mcrypt_enc_get_iv_size($td);
        $iv = mcrypt_create_iv($ivsize, MCRYPT_DEV_URANDOM);
        $key = $this->validateKey($this->encryptionKey, mcrypt_enc_get_key_size($td));

        mcrypt_generic_init($td, $key, $iv);

        $encryptedData = mcrypt_generic($td, $this->encode($data));
        mcrypt_generic_deinit($td);

        $result = $iv.$encryptedData;
        $this->cwsDebug->dump('Encrypted data', $result);

        return $result;
    }
public function encrypt($data)
    {
        $this->cwsDebug->titleH2('Encrypt data');

        if (empty($this->encryptionKey)) {
            $this->error = 'You have to set the encryption key...';
            $this->cwsDebug->error($this->error);

            return;
        }

        if (empty($data)) {
            $this->error = 'Data empty...';
            $this->cwsDebug->error($this->error);

            return;
        }

        $this->cwsDebug->labelValue('Encryption key', $this->encryptionKey);
        $this->cwsDebug->dump('Data', $data);

        $td = mcrypt_module_open(MCRYPT_BLOWFISH, '', MCRYPT_MODE_CFB, '');

        $ivsize = mcrypt_enc_get_iv_size($td);
        $iv = mcrypt_create_iv($ivsize, MCRYPT_DEV_URANDOM);
        $key = $this->validateKey($this->encryptionKey, mcrypt_enc_get_key_size($td));

        mcrypt_generic_init($td, $key, $iv);

        $encryptedData = mcrypt_generic($td, $this->encode($data));
        mcrypt_generic_deinit($td);

        $result = $iv.$encryptedData;
        $this->cwsDebug->dump('Encrypted data', $result);

        return $result;
    }
public function encrypt ( $ data ) { $ this -> cwsDebug -> titleH2 ( 'Encrypt data' ) ; if ( empty ( $ this -> encryptionKey ) ) { $ this -> error = 'You have to set the encryption key...' ; $ this -> cwsDebug -> error ( $ this -> error ) ; return ; } if ( empty ( $ data ) ) { $ this -> error = 'Data empty...' ; $ this -> cwsDebug -> error ( $ this -> error ) ; return ; } $ this -> cwsDebug -> labelValue ( 'Encryption key' , $ this -> encryptionKey ) ; $ this -> cwsDebug -> dump ( 'Data' , $ data ) ; $ td = mcrypt_module_open ( MCRYPT_BLOWFISH , '' , MCRYPT_MODE_CFB , '' ) ; $ ivsize = mcrypt_enc_get_iv_size ( $ td ) ; $ iv = mcrypt_create_iv ( $ ivsize , MCRYPT_DEV_URANDOM ) ; $ key = $ this -> validateKey ( $ this -> encryptionKey , mcrypt_enc_get_key_size ( $ td ) ) ; mcrypt_generic_init ( $ td , $ key , $ iv ) ; $ encryptedData = mcrypt_generic ( $ td , $ this -> encode ( $ data ) ) ; mcrypt_generic_deinit ( $ td ) ; $ result = $ iv . $ encryptedData ; $ this -> cwsDebug -> dump ( 'Encrypted data' , $ result ) ; return $ result ; }
Generate a symectric encryption string with the blowfish algorithm and
an encryption key in CFB mode.
Please be advised that you should not use this method for truly sensitive data.

@param string $data : The data to encrypt

@return string|null : The encrypted string
Generate a symectric encryption string with the blowfish algorithm and an encryption key in CFB mode . Please be advised that you should not use this method for truly sensitive data .