There are many ways in which locks and keys get damaged over time. Depending on what kind of lock you have, it requires different kinds of attention and materials in its maintenance. A lot of the time, simple maintenance on a lock can be so complicated that the work requires a call to your local locksmith company, but there’s no harm (if done properly) in doing what you can to make sure the lock works for longer, before you need to have a professional come take a look at it.
Moisture is somewhat acidic, and doesn’t take very long to rust and corrode a lock. Especially bolt locks which have keyholes that are more exposed than say, pin tumbler cylinders. But cleaning and lubricating is not a task to be taken lightly since it often requires the dismantling of the lock, which can be done by anyone, but the reassembling is extremely complicated and requires a locksmith.
Lubrication maintenance can still be done, albeit sparingly, and different locks need different kinds of lubrication. Lever locks are made of brass and require little to no lubrication, but they can benefit from a very slight wiping of white grease from time to time. Spring latches also like white grease, but in slightly larger quantities.
For very old locks, you can use a dry, corrosive resistant lubricant is best, and it must be used sparingly.
Pin tumbler cylinder locks require just a puff of graphite powder to keep them from wearing, or even better (if you struggle with being frugal) then coat the key in graphite powder and use it in the lock.
Over lubricating a lock can lead to a severe buildup of dirt in the mechanisms which will stop them from working, and then require a local locksmith to clean it. So use lubricants correctly and wisely if you don’t want to damage your locks.
Some very old locks are drilled right through the door, and so they cannot be removed for inspections or cleaning without being damaged. If you are the proud owner of one of these glorious contraptions and it’s not working properly, I’m sorry… maybe it’s time to put it out of service.
In terms of key maintenance, modern day keys are fairly cheaply copied if the master pattern is good enough, and so having them swing from your keychain is not such a problem. But keys for very old locks are generally of an exceptionally high quality and cost a small fortune to replace, if a locksmith is prepared to do it. If you have and use one of these keys, take exceptional care of it, because you may find it cheaper to replace the entire lock than it would be to replace the key. Keep the key clean, if for any reason it is greasy, don’t use it in the lock without cleaning it properly, and constantly inspect the lock, as well as you can, for dirt and foreign bodies.