Updated on 2024-05-09 GMT+08:00

AK/SK Authentication

Generating an AK and SK

  1. Register with Huawei Cloud and log in to the management console.
  2. Click the username and choose My Credentials from the drop-down list.
  3. In the navigation pane, choose Access Keys.
  4. Click Create Access Key.
  5. Enter the SMS or email verification code and click OK to download the access key. Keep the access key secure.

Signing a Request

API requests sent by third-party applications to Huawei Cloud must be authenticated using signatures.

Preparation

  1. Download the APIG signing tool and decompress it.
  2. Create a Java project and reference the decompressed JAR file to the dependency path.

Procedure

  1. Create a com.cloud.sdk.DefaultRequest (JAVA) request used for signing.
  2. Set the destination API URL, HTTPS method, and content of DefaultRequest.
  3. Sign DefaultRequest.
    1. Call SignerFactory.getSigner(String serviceName, String regionName) to obtain a signature tool instance.
    2. Call Signer.sign(Request<?> request, Credentials credentials) to sign the request created in step 1.

      The following code shows the details.

      // Select the signing algorithm for signing the request.
       Signer signer = SignerFactory.getSigner(serviceName, region);   
      // Sign the request. The request will change after being signed.
       signer.sign(request, new BasicCredentials(this.ak, this.sk));
  4. Convert the request signed in the previous step to one that can be used to make an API call and copy the header of the signed request to the new request.
  5. For example, for Apache HttpClient, convert DefaultRequest into HttpRequestBase and copy the header of the signed DefaultRequest to HttpRequestBase.