Added function to generate keyfile.