Make function to generate key file