Google, Stripe and many other companies have public API key and Secret API key.
It is easy to generate random strings but my question is, how can I generate public and secret keys, store them and use them properly?
The public API key is to tell who the user is and the secret is to confirm their identity.
My flow is as follow: - User create an account - User activates a service (in-house) - The service return a public and a secret API key (UARRHAtPtJcLxx5RmMWo9oTrca4gRt2k, C9YS7Mhzichq2vqBuRkNJxkNci5W2Xua) - User use the public key on his/her website and the private key on the server-side
I am using nodejs and the public key is generated on demand, when the user asks for an API key:
let public = await crypto.randomBytes(32).toString('base64');
Storing the secret in a database would be like storing password in plaintext. I presume we do not want this and it needs to be hashed somehow. Do I generate a "private" key and hash it using argon2 for example? The user will never be able to see his/her key again and will need to save it right away, is this good practice?
I couldn't find much information on how this is suppose to work.