How to generate Secure api key with embeded filter

Using the REST API how can i generate the Secure API key in my server? So that i can pass it on to my client(browser) to use that apikey in all the query that user does.

From what I read here and here (which also provides the method) the best way to create Secured API keys is like this.