It’s an interesting case, and I don’t think it’s necessarily obvious. A judge can compel someone to provide the contents of a locked safe. What’s the difference? Just because in some cases the state might be able to open a safe themselves without help from the defendant, it seems that the operative portion of the event is the valid court order. If (hypothetically) someone had an unbreakable safe such that the only way in was the use of a combination I think that same court could compel the defendant to open it or provide the combination. Is that self-incrimination? Or is it contempt of court to refuse?
It’s a good question. It seems clear too that if somebody just “forgets” the encryption key it’s impossible to prove otherwise. I can’t see how someone could be held in contempt for a failure to recall something. The court can’t compel someone to do the impossible.
I draw the line using a “rag doll” model. They can compel fingerprints, physical keys, DNA, etc. insofar as they can manipulate your limp unresitive (albeit uncooperative) body to take fingerprints, extract keys from pockets, snip a hair, extract a blood sample, etc. They cannot, however, compel you to act on their behalf and against your own interests - to wit, they cannot demand you speak (type, write, press buttons) words the whole point of which can and will be used against you. If they can find the password, fine; if it exists only in your head, no.
“Rubber hose cryptology” (to wit: threaten you with harm unless you confess the keyword) is not an acceptable legal tool.