Like the map, the key was made at an unknown time by Thrór and his son Thráin before the fall of the Lonely Mountain. It was kept by Thrór and then Thráin with the map. When Thráin was captured by the Necromancer, it was given to Gandalf in TA 2850 by Thráin just before he died in the dungeons of the Necromancer.  The key and the map was presented to Thorin the day that he and his fellow Dwarves visited Bilbo at Bag End in late April, 2941, and from that moment he kept it fastened to a chain around his neck.
When Thorin and Company were at the place of Side-door, time began to pass and the Sun began to fall and the Moon appeared and a hole appeared about three feet from the ground. As the Dwarves attempted to force the rock without success, Bilbo suddenly remembered the key Gandalf gave Thorin and told Thorin to use it to open the door before the light disappeared that revealed it. Thorin took the key and put it in the keyhole which caused the door-cracks to appear and the door to open.
Portrayal in adaptations
In Peter Jackson's The Hobbit: An Unexpected Journey, the key is ornately wrought, with Dwarven runes engraved on both sides of the shaft. When translated, these runes read "Durin's Heir", a reference to Thorin's ancestor, Durin the Deathless.