Theorem (Uniqueness of Primes of Form 4k+1 as Sum of Two Squares)
The expression of a prime of form
$4k+1$
as a sum of two squares is unique except for the order of the squares.
Proof
Suppose
$p=a^2+b^2=c^2+d^2$
with
$a \gt b \gt 0, c \gt d \gt 0$
.
$a^2d^2-b^2c^2=(p-b^2)d^2-b^2(p-d^2)=p(d^2-b^2) \equiv 0 \; (mod \; p)$

Then
$(ad-bc)(ad+bc) \equiv 0 \; (mod \; p)$
.
Euclid's Lemma tells us that either
$p | (ad-bc)$
or
$p | (ad+bc)$
.
Suppose
$p | (ad+bc)$
. Each of
$a, \; b, \; c, \; d$
is strictly between 0 \nd
$\sqrt{p}$
so
$0 \lt ad+bc \lt 2p$
. It must be the case then that
$ad+bc=p$
but then
$p^2=(a^2+b^2)(c^2+d^2)=(ad+bc)^2+(ac-bd)^2=p^2+(ac-bd)^2$

But then
$ac-bd=0$
and since
$a \gt b, \; c \gt d$
we must have
$ac \gt bd$
so we have a contradiction, and
$p | (ad-bc)$
.
Since
$0 \lt a, \; b, \; c, \; d \lt \sqrt{p}$
we have
$=p \lt ad-bc \lt p$
so
$ad=bc$
. Then
$a | bc$
but
$gcd(a,b)=1$
so
$a | c$
. Putting
$c=ka$
the equation
$ad=bc$
becomes
$ad=bka \rightarrow d=bk$
and
$p^2=c^2+d^2=(ak)^2+(kb)^2=k^2(a^2+b^2)=k^2p$
.
Hence
$k=1$
and
$a=c, \; b=d$
.