public function decrypt($crypttext, $key = null) {
        if(null !== $key) {
            $this->_key = md5($key);
        }

        $crypttext = base64_decode($crypttext);
        $plaintext = '';
        $td        = mcrypt_module_open($this->_cypher, '', self::MODE, '');
        $ivsize    = mcrypt_enc_get_iv_size($td);
        $iv        = substr($crypttext, 0, $ivsize);
        $crypttext = substr($crypttext, $ivsize);
        if ($iv) {
            mcrypt_generic_init($td, $this->_key, $iv);
            $plaintext = mdecrypt_generic($td, $crypttext);
        }
        return trim($plaintext);
    }
public function decrypt($crypttext, $key = null) {
        if(null !== $key) {
            $this->_key = md5($key);
        }

        $crypttext = base64_decode($crypttext);
        $plaintext = '';
        $td        = mcrypt_module_open($this->_cypher, '', self::MODE, '');
        $ivsize    = mcrypt_enc_get_iv_size($td);
        $iv        = substr($crypttext, 0, $ivsize);
        $crypttext = substr($crypttext, $ivsize);
        if ($iv) {
            mcrypt_generic_init($td, $this->_key, $iv);
            $plaintext = mdecrypt_generic($td, $crypttext);
        }
        return trim($plaintext);
    }
public function decrypt ( $ crypttext , $ key = null ) { if ( null !== $ key ) { $ this -> _key = md5 ( $ key ) ; } $ crypttext = base64_decode ( $ crypttext ) ; $ plaintext = '' ; $ td = mcrypt_module_open ( $ this -> _cypher , '' , self :: MODE , '' ) ; $ ivsize = mcrypt_enc_get_iv_size ( $ td ) ; $ iv = substr ( $ crypttext , 0 , $ ivsize ) ; $ crypttext = substr ( $ crypttext , $ ivsize ) ; if ( $ iv ) { mcrypt_generic_init ( $ td , $ this -> _key , $ iv ) ; $ plaintext = mdecrypt_generic ( $ td , $ crypttext ) ; } return trim ( $ plaintext ) ; }
Decrypt a previously encrypted text

@param string $crypttext
@param null|string $key User specified key
@return string
Decrypt a previously encrypted text