If the judge did not grant the stay, you could turn over the key but explain that you were not waiving your Fifth Amendment rights. Then when you were found guilty, you could appeal, argue that your Fifth Amendment rights were violated, and get your conviction overturned. Alternatively, you could not turn over the key, go to jail for contempt, and wait for your lawyer to appeal the contempt finding and get you out of jail.
2 (re: password vs. physical key in secret place) - in some cases, the act of producing a physical key may actually be protected under the Fifth Amendment. If the police can show that you know the key's location, then by forcing you to produce the key they are not forcing you to give any testimony, and you have no Fifth Amendment protection. However, if they ask you for a key but can't prove that you have it, they are asking you to create implicit testimony. The implicit testimony is "I know where the key is." If this testimony would end up incriminating you, the it is protected by the Fifth Amendment and you don't have to produce the key.