Yes, that should work. Assuming, of course, the names of the keys are prisonkeylight_1 and prisonkeydark_1, and the door name is mansion_3. You can also add in a sanity boost inside the if statement, and anything else you want to happen, since it basically works as its own function. For example, if you wanted it to play a door unlocking sound, you would just place the PlaySoundAtEntity function with the SetSwingDoorLocked function.
Edit: whoops, sorry, didn't see that this had reached 2 pages. Ignore me
Edit 2: If you are getting an error that says unexpected end of file, it means you need to go back and look at where your "{ }" are, and make sure they are closing properly. Also check to make sure semicolons are placed in the right spots.