Over Gaussian integers, can every prime be $p \equiv 1 \text{ mod }4$ be expressed as $(a + bi)(a - bi)$ in almost unique manner? Over the Gaussian integers, can every prime $p \equiv 1 \text{ mod }4$ be expressed as $(a + bi)(a - bi)$ in an almost unique manner, unique up to negation of $a$ and/or $b$?
 A: Yes. The domain of Gaussian integers, $\mathbb{Z}[i]$, is a unique factorization domain, which means that each nonzero, non-unit number in that domain can be factored into primes uniquely without regard for order or multiplication by units. The units of $\mathbb{Z}[i]$ are $i$, 1, $-i$, $-1$.
Fermat (or was it Euler?) proved that if $p = 2$ or $p \equiv 1 \pmod 4$ is a positive real prime number, then $p = a^2 + b^2$, where $a$ and $b$ are purely real integers. You have noticed the connection to the norm function, which means that these numbers that are prime in $\mathbb{Z}$ are composite in $\mathbb{Z}[i]$, since then $p = (a - bi)(a + bi)$.
But then $(b - ai)(b + ai) = p$ seems to be another factorization. But note that $(b - ai)i = a + bi$ and $i$ is a unit of this domain. Likewise, $(b + ai)(-i) = a - bi$. What seems to be another factorization is in fact the same factorization, just with different units.
So for example, $5 = (2 - i)(2 + i) = (1 - 2i)(1 + 2i)$. This does not represent two distinct factorizations because $(1 - 2i)i = 2 + i$. It's the same principle why $21 = 3 \times 7 = -3 \times -7$ does not represent two distinct factorizations either.
A: First of all one must clearly stress that the decomposition is taken in $\textbf{Z}[i]$, not in $\textbf{Q}(i)$. Because if $p = (a + ib)(a - ib) = N(z)$, where $N$ denotes the norm map of $\textbf{Q}(i)/\textbf{Q}$ and $z = a + ib$, any $u$ of norm 1 will also give $p = N(uz)$. The elements $u$ of norm $1$ in $\textbf{Q}(i)$ are given e.g. by Hilbert 90, they are of the form $u = (x + iy)/(x - iy)$, so there is certainly not unicity in $\textbf{Q}(i)$. However, the elements $u$ in $\textbf{Z}[i]$ of norm $1$ are invertible, and are easily shown to form the cyclic group generated by $i$, so that up to these, there is unicity in $\textbf{Z}[i]$. 
To answer user1952009's other question, the argument for proving that any $p$ congruent to $1 \bmod 4$ is a sum of squares relies on the decomposition of the ideal $\langle p \rangle$ into a product of prime ideals in $\textbf{Z}[i]$. General criteria for  quadratic fields show that $\langle p \rangle = \mathfrak P. \mathfrak P'$, hence taking norms yields $N(\mathfrak P) N(\mathfrak P') = p^2$. As $N(\mathfrak P)$ and $N(\mathfrak P')$ are not $1$, necessarily $N(\mathfrak P) = N(\mathfrak P') = p$. Since $\textbf{Z}[i]$ is a PID, $\mathfrak P$ is of the form $(a + ib)$, and we are done.
A: Yes, every integer prime $p$ with $p \equiv 1$ (mod $4$) can be written in the form $p = a^{2}+b^{2} = (a+bi)(a-bi)$ for integers $a$ and $b$, and given one choice of $a,b$ the only other possibilities in place of $a+ib$ have the form $\pm (a+ib)$ or $\pm i(a+ib)= \pm (-b +ai)$. This is a Theorem of Fermat and Euler.
