# Authentication

Learn how to authenticate your API requests in a few easy steps. There are 3 different types of API authentication methods.

---

### [How to get your API Key?](/content/docs/shipping/quickstart/authentication#how-to-get-your-api-key/index.html)

1. [Log in](https://organization.automizely.com/welcome) to your AfterShip account. (If you don’t have it, click _**Create account**_ at the bottom of the login page to create one for FREE.)
2. Visit [API keys](https://organization.automizely.com/api-keys).
3. Click _**Create an API key**_ and follow the given instructions to generate your API key.

[Get API Key](https://organization.automizely.com/api-keys)

## [1. API Key](/content/docs/shipping/quickstart/authentication#1-api-key/index.html)

The API Key method is a more straightforward authentication method that only verifies whether the API Key value is correct or not.

### [Required Headers](/content/docs/shipping/quickstart/authentication#required-headers/index.html)

| Header Name | Description | Example |
| --- | --- | --- |
| as-api-key | The API key retrieved from the developer portal | 6e759c509d174859be1fb856c4ab646e |

## [2. AES](/content/docs/shipping/quickstart/authentication#2-aes/index.html)

### [Required Headers](/content/docs/shipping/quickstart/authentication#required-headers-1/index.html)

| Header Name | Description | Example |
| --- | --- | --- |
| as-api-key | The API key retrieved from the developer portal | 6e759c509d174859be1fb856c4ab646e |
| as-signature-hmac-sha256 | Computed signature | bcfba53d95454ada96b9658c4f178764 |
| date | UTC time in RFC 1123 format.<br>Kindly note that the calculated signature is only valid for 3 minutes before or after the datetime indicated in this key. | Sun, 06 Nov 1994 08:49:37 GMT |
| content-type | Content type string.<br>If the request body is empty, set content_type to an empty string | application/json |

### [Calculating the signature](/content/docs/shipping/quickstart/authentication#calculating-the-signature/index.html)

Calculate the signature using the flow given below:

1. Construct [SignString](/content/docs/shipping/quickstart/authentication/sign-string/index.html).
2. Get the required API secret from the API key generation page.
3. Calculate the hash of `SignString` with `hmac-sha256` algorithm.
4. Encode the result in base64 format; the output will be the required signature.

## [3. RSA](/content/docs/shipping/quickstart/authentication#3-rsa/index.html)

### [Required Headers](/content/docs/shipping/quickstart/authentication#required-headers-2/index.html)

| Header Name | Description | Example |
| --- | --- | --- |
| as-api-key | The API key retrieved from the developer portal | 6e759c509d174859be1fb856c4ab646e |
| as-signature-rsa-sha256 | Computed signature | bcfba53d95454ada96b9658c4f178764 |
| date | UTC time in RFC 1123 format.<br>Kindly note that the calculated signature is only valid for 3 minutes before or after the datetime indicated in this key. | Sun, 06 Nov 1994 08:49:37 GMT |
| content-type | Content type string.<br>If the request body is empty, set content_type to an empty string | application/json |

### [Public API secret](/content/docs/shipping/quickstart/authentication#public-api-secret/index.html)

An RSA key pair (public and private) is required for generating this API key.

Follow these steps to generate an RSA key pair:

1. If using Mac or Linux, open Terminal. For Windows, use Git Bash or WSL2.

2. Run:

```
   ssh-keygen -t rsa -m PEM -f key
   ```

Leave the passphrase blank.

3. This creates RSA key pair files (key and key.pub)

4. Generate the public key:

```
   ssh-keygen -e -f key.pub -m PEM > key.pem
   ```

This create `key.pem`

5. View `key.pem` content by typing `cat key.pem`. Copy it, and paste it into the Enter the public API secret box in the AfterShip Organization portal.

### [Calculating the signature](/content/docs/shipping/quickstart/authentication#calculating-the-signature-1/index.html)

Follow this flow:

1. Construct [SignString](/content/docs/shipping/quickstart/authentication/sign-string/index.html).
2. Get the private key (the pair of the public key configured in the AfterShip Organization portal).
3. Calculate the digest of SignString with the `RSA_SIGN_PSS_2048_SHA256` algorithm using the previously generated private key. Refer to [RFC 8017](https://datatracker.ietf.org/doc/html/rfc8017) for `RSASSA-PSS` signature details.
4. Encode the result in base64 format; this gives you the required signature.
