src/SecureString.php
protected function encrypt($str, $method, $password, $iv = '', $throw = false) {
        if ($iv === '') {
            $iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length($method));
        }
        // Encrypt the string.
        $encrypted = openssl_encrypt($str, $method, $password, OPENSSL_RAW_DATA, $iv);

        if ($encrypted === false) {
            return $this->exception($throw, "Error encrypting the string.", 400);
        }

        $str = static::base64urlEncode($encrypted);
        $this->pushString($str, static::base64urlEncode($iv));

        return $str;
    }
protected function encrypt($str, $method, $password, $iv = '', $throw = false) {
        if ($iv === '') {
            $iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length($method));
        }
        // Encrypt the string.
        $encrypted = openssl_encrypt($str, $method, $password, OPENSSL_RAW_DATA, $iv);

        if ($encrypted === false) {
            return $this->exception($throw, "Error encrypting the string.", 400);
        }

        $str = static::base64urlEncode($encrypted);
        $this->pushString($str, static::base64urlEncode($iv));

        return $str;
    }
Encrypt a string with {@link openssl_encrypt()}.

@param string $str The string to encrypt.
@param string $method The encryption cipher.
@param string $password The encryption password.
@param string $iv The input vector.
@param bool $throw Whether or not to throw an exception on error.
@return string Returns the encrypted string.