How do I generate and set node identity?

So I am looking to have my application generate a new key on first run and then from there forward use the key that was saved in boltdb.

What I have so far is the code to detect that the database just got created so that the initial data can be populated. What I need to be able to generate a new key and then store that key. If the database exists all I need to do is read the key into a variable before starting libp2p. The problem is that a lot of the information I see online for the generation and setting of keys seems dated. What is the modern approach to creating a loading a key?