tags:

views:

389

answers:

5

I get to see this word in almost every cross service application these days.

What exactly is an API key and what are its uses

Also please explain the difference between public and private API keys.

+2  A: 

An API key is a unique value that is assigned to a user of this service when he's accepted as a user of the service.

The service maintains all the issued keys and checks them at each request.

By looking at the supplied key at the request, a service checks whether it is a valid key to decide on whether to grant access to a user or not.

Developer Art
so what about the public and private one?
OrangeRind
Public and private keys come from the domain of encryption and have something to do with asymmetric encryption. I've never heard these terms used in the sense of API keys.
Developer Art
+4  A: 

Very generally speaking:

An API key simply identifies you.

If there is a public/private distinction, then the public key is one that you can distribute to others, to allow them to get some subset of information about you from the api. The private key is for your use only, and provides access to all of your data.

timdev
most of the time they look like hashes. is my observation correct?
OrangeRind
The can be generated however you want, as long as they are unique. A hash of some data seems like a reasonable way to generate one, yes.
Matthew Scharley
Yes, they look like hashes. After all, you don't want them to be easy to guess.
timdev
More or less - most bog standard API keys are generated by hashing some pseudorandom value and performing some standard plain-text encoding on the result, e.g. base16, base64 etc.
Rob
Thanks !
OrangeRind
+8  A: 

What "exactly" an API key is used for depends very much on who issues it, and what services it's being used for. By and large, however, an API key is the name given to some form of secret token which is submitted alongside web service (or similar) requests in order to identify the origin of the request. The key may be included in some digest of the request content to further verify the origin and to prevent tampering with the values.

Typically, if you can identify the source of a request positively, it acts as a form of authentication, which can lead to access control. For example, you can restrict access to certain API actions based on who's performing the request. For companies which make money from selling such services, it's also a way of tracking who's using the thing for billing purposes. Further still, by blocking a key, you can partially prevent abuse in the case of too-high request volumes.

In general, if you have both a public and a private API key, then it suggests that the keys are themselves a traditional public/private key pair used in some form of asymmetric cryptography, or related, digital signing. These are more secure techniques for positively identifying the source of a request, and additionally, for protecting the request's content from snooping (in addition to tampering).

Rob
Well put! However, in my somewhat limited experience, the public/private distinction has nothing to do with public key crypto. The "public" keys I've seen are typically "access lite" -- in other words, a key you can distribute to grant third parties access to non-sensitive data, without giving away the keys to the kingdom.
timdev
@Rob +1 for the detailed answer@tim +1 for the aferthought!
OrangeRind
@tim - agreed. I think the more common approach I've seen is to have a private digest key.
Rob
+1  A: 

API keys are just one way of authenticating users of web services.

GG
A: 

See also my answer to this question on the distinction between public and secret components of an API key: http://stackoverflow.com/questions/1482472/when-working-with-most-apis-why-do-they-require-two-types-of-authentication-nam/1501112#1501112

Eugene Osovetsky