I am trying to learn about RSA digital signatures, and have a question about the verification process.
My understanding of the set-up is the following:
The signer chooses two secret primes $p$ and $q$, and a verification exponent $e$ satisfying $\gcd(e,(p-1)(q-1))=1$, then publishes $N=pq$ and $e$.
The signer computes the secret signing exponent $d$ such that $$de\equiv1\pmod{(p-1)(q-1)},$$
signs the document $D$ by computing $$S\equiv D^d\pmod N,$$ and sends $D$ and $S$ to the verifier.
Here is what I am having a trouble.
I read that the verifier computes $$S^e \pmod N$$ and compares the result to $D$. If the result is indeed equal to $D$, then the verifier is convinced that the signature is valid. My question is, why is the following supposed to be the case? $$S^e\equiv (D^d)^e\equiv D \pmod{N}$$
I see that if $D$ and $N$ are relatively primes, then Euler's formula can be used. But that means we can only sign a document $D$ that is relatively prime to the modulus $N$?