[1] (b) Every alien 10/ (other than a nonimmigrant described in subparagraph (L) or (V) of section 101(a)(15), and other than a nonimmigrant described in any provision of section 101(a)(15)(H)(i) except subclause (b1) of such section) shall be presumed to be an immigrant until he establishes to the satisfaction of the consular officer, at the time of application for a visa, and the immigration officers, at the time of application for admission, that he is entitled to a nonimmigrant status under section 101(a)(15) .
When you're a foreigner attempting to enter the USA, they can simply deny you entry for failing to do what they want. US CBP has the authority to make arbitrary decisions not to admit foreigners, and CBP faces almost no scrutiny.
Most other countries give their border guards similar authority with respect to foreigners not entitled to enter by some treaty (e.g. EU).
But in the UK, you can go to jail for not disclosing your cryptographic keys. https://en.wikipedia.org/wiki/Key_disclosure_law#United_King...
Here is a story of a person who went to jail for not disclosing his keys: http://www.theregister.co.uk/2009/11/24/ripa_jfl/?page=1 He said he kept silent "because of principle", but I guess he might also have gone to jail if he told them "I don't remember" - Officers would not believe him anyway.
If you can call a lawyer and don't mind waiting several hours, you can challenge it. However most people don't have a lawyer and don't know what to do and are afraid of the officers.
I legitimately don't know many of my passwords, there's no legal obligation to know them, and the law generally cant compel you to do impossible things (eg, tell them something you don't know).
They can subpoena my password safe, just like any other file on my computer, and possibly require I unlock it (this is disputed), but I don't see any reason they can demand I reproduce the contents of the safe that I don't know.