Str.php
public static function encrypt($data, $key, $cipher = MCRYPT_RIJNDAEL_128, $mode = MCRYPT_MODE_CBC)
    {
        $data       =   serialize($data);
        $key        =   hash('sha256', $key, true);
        $iv_size    =   mcrypt_get_iv_size($cipher, $mode);
        $iv         =   mcrypt_create_iv($iv_size, MCRYPT_RAND);

        return  base64_encode(serialize(array($iv, mcrypt_encrypt($cipher, $key, $data, $mode, $iv))));
    }
public static function encrypt($data, $key, $cipher = MCRYPT_RIJNDAEL_128, $mode = MCRYPT_MODE_CBC)
    {
        $data       =   serialize($data);
        $key        =   hash('sha256', $key, true);
        $iv_size    =   mcrypt_get_iv_size($cipher, $mode);
        $iv         =   mcrypt_create_iv($iv_size, MCRYPT_RAND);

        return  base64_encode(serialize(array($iv, mcrypt_encrypt($cipher, $key, $data, $mode, $iv))));
    }
Encrypt using mcrypt

@param   mixed   $data   the data to encrypt, supports any type "it will be serialized"
@param   string  $key    the secrt key
@param   string  $cipher the cipher
@param   string  $mode   the mode
@return  string