When you initiate requests to OSS, include a V4 signature in the Authorization request header. This ensures successful authentication. You can use the OSS SDK to initiate requests, because it implements the complex V4 signature algorithm. Only implement the V4 signature algorithm yourself if you cannot use the SDK. For more information, see this document.
SDK Signature Implementation
If you implement the V4 signature algorithm yourself, refer to the SDK’s V4 signature implementation first.
SDK | V4 Signature Implementation |
Authorization Request Header
When you initiate a request to OSS, include a signature in the Authorization request header to verify the request.
The format of the Authorization request header is as follows:
Authorization: OSS4-HMAC-SHA256 Credential=<AccessKeyId>/<SignDate>/<SignRegion>/oss/aliyun_v4_request, AdditionalHeaders=<AdditionalHeadersVal>, Signature=<SignatureVal>The following table describes the Authorization request header:
Components | Description |
OSS4-HMAC-SHA256 | Specifies the algorithm for signature calculation. This string defines the OSS V4 signature version (OSS4) and the signature algorithm (HMAC-SHA256). Provide this value when using V4 signatures for authentication. |
Credential | AccessKey ID and scope information (including the date, region, and cloud product used for signature calculation). Provide this field when using V4 signatures for authentication. Format is as follows: Where:
|
AdditionalHeaders | Specify optional request headers for signature calculation (do not specify required headers). Include only lowercase header names, sorted lexicographically and separated by semicolons (;). Example: |
Signature | The calculated signature. Provide this field when using V4 signatures for authentication. Example of a 256-bit signature value, represented by 64 lowercase hexadecimal digits: |
Signature Calculation
After OSS receives a request, it calculates the signature and compares it with the signature in the Authorization request header. If the signatures match, the request succeeds. Otherwise, the request fails.
Signature Calculation Process
The following figure shows the signature calculation process:
The signature calculation process consists of three steps:
Construct a canonical request: Format the request according to the OSS signature specifications to create a canonical request.
Construct a string-to-sign: Process the canonical request to generate a string-to-sign.
Calculate the signature: Perform multiple hash operations on the AccessKey Secret to generate a derived key. Then, use the derived key to calculate the string-to-sign, which yields the final signature.
1. Construct a Canonical Request
The format of the canonical request is as follows:
HTTP Verb + "\n" +
Canonical URI + "\n" +
Canonical Query String + "\n" +
Canonical Headers + "\n" +
Additional Headers + "\n" +
Hashed PayLoadThe canonical request is defined as follows:
Parameter | Description |
HTTP Verb | The HTTP request method, such as PUT, GET, POST, HEAD, DELETE, and OPTIONS. |
Canonical URI | The URI-encoded resource path. The resource path does not include the query string. Do not encode forward slashes (
|
Canonical Query String | URI-encoded query parameters, sorted lexicographically.
|
Canonical Headers | The list of request headers. Request headers fall into three categories:
Format is as follows: Example: |
Additional Headers | Specify optional request headers for signature calculation (do not specify required headers). Include only lowercase header names, sorted lexicographically and separated by semicolons (;). This must be consistent with Example: |
Hashed PayLoad | The hexadecimal representation of the SHA256 hash value of the request payload. Only |
2. Construct a String-to-Sign
The format of the string-to-sign is as follows:
"OSS4-HMAC-SHA256" + "\n" +
TimeStamp + "\n" +
Scope + "\n" +
Hex(SHA256Hash(<CanonicalRequest>))The following table describes the string-to-sign:
Parameter | Description |
OSS4-HMAC-SHA256 | The signature hash algorithm. Its value must be |
TimeStamp | The current UTC time. Its format must be ISO8601, such as |
Scope | The parameter set for deriving the key. This set specifies the date, region, and service. Therefore, a signature calculated with the derived key is valid only for the specified date, region, and service. Format is as follows: Description is as follows:
|
CanonicalRequest | The constructed canonical request. |
3. Calculate the Signature
Signature calculation consists of two steps:
Calculate the
SigningKey.DateKey = HMAC-SHA256("aliyun_v4" + SK, Date); DateRegionKey = HMAC-SHA256(DateKey, Region); DateRegionServiceKey = HMAC-SHA256(DateRegionKey, "oss"); SigningKey = HMAC-SHA256(DateRegionServiceKey, "aliyun_v4_request");SK: The AccessKey Secret used in the signature.Date: The date used in the signature, inYYYYMMDDformat. It must match theSignDatein the string-to-sign.Region: The region ID used for the signature, such ascn-hangzhou. It must match theSignRegionin the string-to-sign.
Use the
SigningKeyand the string-to-sign to calculate theSignature.Signature = HEX(HMAC-SHA256(SigningKey, StringToSign))
Signature Calculation Example
This example uses PutObject to demonstrate signature calculation.
Signature Calculation Parameters
Parameter | Value |
AccessKeyId | LTAI**************** |
AccessKeySecret | yourAccessKeySecret |
Timestamp | 20250411T064124Z |
Bucket | examplebucket |
Object | exampleobject |
Region | cn-hangzhou |
Signature Calculation Process Example
Construct a canonical request.
PUT /examplebucket/exampleobject content-disposition:attachment content-length:3 content-md5:ICy5YqxZB1uWSwcVLSNLcA== content-type:text/plain x-oss-content-sha256:UNSIGNED-PAYLOAD x-oss-date:20250411T064124Z content-disposition;content-length UNSIGNED-PAYLOADConstruct a string-to-sign.
OSS4-HMAC-SHA256 20250411T064124Z 20250411/cn-hangzhou/oss/aliyun_v4_request c46d96390bdbc2d739ac9363293ae9d710b14e48081fcb22cd8ad54b63136ecaCalculate the signature.
Calculate the SigningKey.
NoteFor readability, the
SigningKeyis shown in hexadecimal format below.Different combinations of signature parameters produce different
SigningKeyvalues. This example is for reference only. Use your actual calculation results.
3543b7686e65eda71e5e5ca19d548d78423c37e8ddba4dc9d83f90228b457c76Calculate the Signature.
053edbf550ebd239b32a9cdfd93b0b2b3f2d223083aa61f75e9ac16856d61f23