An application programming interface (API) key is a unique code used by an API to identify the calling user or application. API keys are used to track and control who is using the API and how they are using it, as well as to authenticate and authorize applications — similar to how usernames and passwords work. password. An API key can come in the form of a single key or a set of multiple keys. Users should use API keys properly to improve their overall security against API key theft and avoid related consequences of their API keys being compromised.

Distinguish between API and API key

To understand what an API key is, you must first understand what an API is. An application programming interface or API (Application programming interface) is middleware that allows two or more applications to share information. For example, CoinMarketCap's API allows other applications to retrieve and use cryptocurrency data, such as price, volume, and market capitalization.

An API key comes in many different forms — it can be a single key or a set of keys. Different systems use these keys to authenticate and authorize an application, similar to how usernames and passwords are used. An API key is used by the API client to authenticate the API calling application.

For example, if Binance Academy wants to use the CoinMarketCap API, an API key will be generated by CoinMarketCap and used to authenticate the identity of the Binance Academy (API application) requesting API access. When Binance Academy accesses CoinMarketCap's API, this API key is sent to CoinMarketCap along with the request.

This API key should only be used by Binance Academy and should not be shared or sent to others. Sharing this API key will allow third parties to access CoinMarketCap as Binance Academy, and any third party actions will appear as if they came from Binance Academy.

The API key can also be used by the CoinMarketCap API to confirm whether the application is authorized to access the requested resource. Additionally, API owners use API keys to track API activity, such as request type, traffic, and volume.

What is an API key?

API keys are used to control and track who is using the API and how they are using it. The term “API key” can mean different things to different systems. Some systems have a single code, but others may have multiple codes for a single “API key.”

Thus, an “API key” is a unique code or set of unique codes used by an API to authenticate and authorize the calling user or application. Some codes are used for authentication and some are used to create a cryptographic signature to prove the legitimacy of the request.

These authentication keys are often referred to collectively as “API keys,” while the codes used for cryptographic signatures have a variety of names, such as “private keys,” “public keys,” or “keys.” private". Authentication requires identifying the entities involved and confirming they are who they say they are.

On the other hand, it authorizes specifying the API services that are allowed to be accessed. The functionality of an API key is similar to that of an account username and password; it can also be connected to other security features to improve overall security.

Each API key is typically generated by the API owner for a specific entity (more details below), and each time a call is made to an API endpoint — requiring user authentication or authorization, or both — then the relevant key will be used.

Cryptographic signature

Some API keys use cryptographic signatures as an additional layer of verification. When a user wants to send certain data to the API, a digital signature generated by another key can be added to the request. Using cryptography, the API owner can verify that this digital signature matches the data sent.

Symmetrical and asymmetrical signatures

Data shared through the API can be signed with cryptographic keys, which fall into the following categories:

Symmetric keys

They involve using a secret key to perform both data signing and signature verification. With symmetric keys, the API key and secret key are typically generated by the API owner, and the API service must use the same secret key to verify the signature. The main advantage of using a singular key is that doing so is faster and requires less computing power to generate and verify the signature. A good example of a symmetric key is HMAC.

Asymmetric keys

They involve the use of two keys: a private key and a public key, which are different but cryptographically linked. The private key is used to create the signature and the public key is used to verify the signature. The API key is generated by the API owner but the private and public key pair is generated by the user. The API owner only needs to use the public key to verify the signature, so the private key can remain local and secret.

The main advantage of using asymmetric keys is the greater security of separating the signature generation key and the verification key. This allows external systems to verify the signature without being able to generate the signature. Another advantage is that some asymmetric encryption systems support adding a password to the private key. A typical example is an RSA key pair.

Are API keys secure?

The responsibility for keeping API keys secure lies with the user. API keys are similar to passwords and should be handled with care. Sharing API keys is similar to sharing passwords and therefore should not be done as doing so puts the user's account at risk.

API keys are often targeted in cyberattacks because they can be used to perform critical operations on the system, such as requesting personal information or performing financial transactions. . In fact, there have been cases of crawlers and online database attacks to steal API keys.

The consequences of API key theft can be severe and lead to significant financial losses. Furthermore, because some API keys do not expire, attackers can use them indefinitely after being stolen until the keys themselves are revoked.

How to use API keys properly

Because it grants access to sensitive data, using API keys securely is paramount. You can follow these best practice guidelines for using API keys to improve overall security:

  1. Refresh your API keys as often as possible. This means you should delete your current API key and create a new one. With many systems, it's easy to create and delete API keys. Similar to how some systems require you to change your password every 30 to 90 days, you should rotate your API keys at a similar frequency if possible.

  2. Use an IP whitelist: When you create an API key, create a list of IPs that are allowed to use the key (IP whitelist). You can also specify a list of blocked IPs (IP blacklist). This way, even if your API key is stolen, it cannot be accessed by an unrecognized IP.

  3. Use multiple API keys: Having multiple keys and dividing responsibilities between them reduces security risks, because your security won't depend on a single key with multiple permissions. You can also set different IP whitelists for each key, further reducing security risks.

  4. Store API keys securely: Do not store your keys in public places, on shared computers, or in their original plain text format. Instead, store each one with encryption or a secret manager for better security, and be careful not to accidentally expose them.

  5. Don't share your API keys. Sharing API keys is similar to sharing your password. In doing so, you grant the other party the same authentication and authorization rights as you. If they are compromised, your API key can be stolen and used to break into your account. An API key should only be used between you and the system that generated it.

If your API key is compromised, you need to disable it first to avoid further damage. If there is any financial loss, take a screenshot of key information related to the incident, contact the relevant units, and send a report to the police. This is the best way to increase your chances of recovering any lost funds.

summary

API keys provide core authentication and authorization functions, and users must carefully manage and protect their keys. There are many steps and aspects to ensure the safe use of API keys. In general, you should think of your API key as a password for your account.

Read more:

  • General security principles

  • 5 Common Cryptocurrency Scams and How to Avoid them