A Blank Portal Key is made from a single Blaze Rod and a Name Tag.
A freshly crafted key does nothing on its own. First it must be “attuned” to a dungeon, which is done using an End Portal Frame in a Stronghold.
Steps:
Aim at the dark square in the middle of the block.
When this succeeds, the key becomes linked to a randomly generated dungeon and is now ready to be used.
Once the key is activated:
Dungeon portals can be created in any dimension. When you leave the dungeon and return, you are placed on the block directly in front of the portal frame that currently holds your key – even if the physical portal blocks were destroyed while you were away.
Sometimes the Stronghold End Portal is already fully lit:
You can still use this room to activate keys:
The 3×3 End portal area in the center stays formed, so you do not lose access to The End. This trick can also repair a portal that was messed up with liquids or other blocks: as you remove and replace Eyes, the portal area is recalculated and restored.
Portal Keys behave as follows:
You can rename a key on an anvil without changing where it leads. The actual destination is stored in the key’s NBT data when it is first activated and does not change, even if the item’s display name does.
This page describes only basic keys and behavior.