What gets encrypted, and how the key is derived
Encryption in PDF is handled by a security handler, and in practice almost always the standard security handler defined by the specification. When it is in use, the trailer references an encryption dictionary that records the handler, its revision, the algorithm, the key length and a set of values derived from the passwords. The document structure itself — the object numbers and the cross-reference information — stays readable, because a viewer has to navigate the file before it can decrypt anything. What gets encrypted is the payload: string values and stream data, which is where all the content lives.
The key is not the password. The handler derives an encryption key from the password you supply combined with values stored in the encryption dictionary, then uses that key to decrypt streams. Older revisions derived it through repeated MD5 hashing; the current revision uses a much stronger derivation based on SHA-2 with salting. The stored values let a viewer verify that a supplied password produces the right key without the file ever containing the password itself.
Because content streams are encrypted, an encrypted PDF is genuinely opaque without the key. You cannot extract its text, pull its images, or read the words by opening it in a hex editor. This is ordinary cryptography doing ordinary cryptographic work, and it is the reason a lost open password is a real problem rather than an inconvenience someone can talk their way around.