Application of Optional Sampling Theorem Lets assume that Brownian Motion starts from some point $x$ for which $a<x<b$ holds. Let $\tau=\inf\{t:B_t\not\in [a,b]\}$ be a stopping time. Now I want to prove that for $\theta>0$ ,an appropriate martingale and the Optional Sampling Theorem the following holds; $$\mathbb E[\exp(-\frac{1}{2}\theta^2\tau)|B_0=x]=\frac{\cosh(\theta(x-(a+b)/2))}{\cosh(\theta(b-a)/2)}$$
My first idea was to rewrite the RHS using $\exp$ expressions instead of $\cosh$ expressions but this is only a formal thing. 
My second thought was that it has something to with the result presented here: The Laplace transform of the first hitting time of Brownian motion
So we use $M_t=\exp(\theta B_t-\frac{1}{2}\theta^2 t)$ as the "appropriate integral" and the Laplace transform of $H_a=\inf\{t: B_t>a\}$ but I do not see how these things should be connected, may you have some idea.
 A: The hitting time $H_a$ is not obviously related to the bilateral hitting time $\tau$ hence I fail to see how to use your idea. Instead, a common approach is to consider the function $u$ defined on $(a,b)$ by
$$
u(x)=E_x[\mathrm e^{-\theta^2\tau/2}],
$$ 
where $E_x[\ ]=E[\ \mid B_0=x]$, and to decompose $\tau$ as the independent sum of the first hitting time $\sigma$ of $\{x-z,x+z\}$ and the remaining time $\tau-\sigma$ until $\tau$, where $z$ is positive and small enough to guarantee that $(x-z,x+z)\subseteq(a,b)$. 
The Markov property at time $\sigma$ and the independence of $\tau-\sigma$ and $\sigma$ yield
$$
u(x)=E_x[\mathrm e^{-\theta^2\sigma/2}]\,\tfrac12(u(x+z)+u(x-z)).
$$
The martingale $(M_t)$ you summoned in your question, plus the fact that $B_{\sigma}$ is independent of $\sigma$ and uniform on  $\{x-z,x+z\}$, yield 
$$
E_x[\mathrm e^{-\theta^2\sigma/2}]=\left(\mathrm e^{-\theta x}E_x[\mathrm e^{\theta B_{\sigma}}]\right)^{-1}=\cosh(\theta z)^{-1},
$$
thus,
$$
2\cosh(\theta z)u(x)=u(x+z)+u(x-z).
$$
When $z\to0$, this reads
$$
2(1+\tfrac12\theta^2z^2)u(x)=2u(x)+u''(x)z^2+o(z^2),
$$
hence
$$
u''(x)-\theta^2u(x)=0.
$$
This, together with the boundary condition that $u(a)=u(b)=1$, yields the expression you are after.
