Creating an Encryption Task

Function

This API is used to create an encryption task.

Constraints:

  • Only transcoded files are encrypted.

  • A file to be encrypted must be an .m3u8 or .mpd file.

URI

POST /v1/{project_id}/encryptions

Table 1 Path parameters

Parameter

Mandatory

Type

Description

project_id

Yes

String

Project ID. For details about how to obtain a project ID, see Obtaining a Project ID.

Request Parameters

Table 2 Request header parameters

Parameter

Mandatory

Type

Description

X-Auth-Token

No

String

User token.

The token is obtained by calling the IAM API used to obtain a user token. The token is the value of X-Subject-Token in the response header.

Authorization

No

String

Authentication information. This parameter is mandatory when AK/SK-based authentication is used.

X-Project_Id

No

String

Project ID. This parameter is mandatory when AK/SK-based authentication is used. It is same as the project ID in path parameters.

X-Sdk-Date

No

String

Time when the request is sent. This parameter is mandatory when AK/SK-based authentication is used.

Table 3 Request body parameters

Parameter

Mandatory

Type

Description

input

No

ObsObjInfo object

Storage location of an input file

output

No

ObsObjInfo object

Storage location of an output file

encryption

No

Encryption object

Encryption information

user_data

No

String

Custom user data

Table 4 ObsObjInfo

Parameter

Mandatory

Type

Description

bucket

Yes

String

OBS bucket name

location

Yes

String

Region where an OBS bucket is located. It must be the same as the region where MPC is deployed.

object

Yes

String

File path.

  • If this parameter is used for an input, a specific path must be specified.

  • If this parameter is used for an output, only the directory for storing the outputs needs to be specified.

file_name

No

String

Name of an output file. This parameter is valid only for packaging tasks.

  • If this parameter is specified, the output object name is object/file_name.

  • If this parameter is not specified, the output object name is object/xxx, where xxx is allocated by MPC.

Table 5 Encryption

Parameter

Mandatory

Type

Description

hls_encrypt

No

HlsEncrypt object

Encryption parameters for HLS videos

Table 6 HlsEncrypt

Parameter

Mandatory

Type

Description

key

Yes

String

Content encryption key, which is in base64Binary format

url

Yes

String

Address of Key Management Service (KMS) used by the tenant

iv

No

String

Initial vector, which is a random number in base64Binary format

algorithm

No

String

Encryption algorithm.

Possible values are:

  • AES-128-CTR

  • AES-128-CBC

  • SM4CBC

Default value: AES-128-CTR

Response Parameters

Status code: 202

Table 7 Response body parameters

Parameter

Type

Description

task_id

String

Task ID

Status code: 400

Table 8 Response body parameters

Parameter

Type

Description

error_code

String

Error code

error_msg

String

Error description

Example Requests

POST https://{endpoint}/v1/{project_id}/encryptions
{
    "output": {
        "bucket": "obs-bucket06",
        "location": "region1",
        "object": "sswoutput"
    },
    "input": {
        "bucket": "vostest",
        "location": "region1",
        "object": "vos_video/hls/index.m3u8"
    },
    "encryption": {
        "hls_encrypt": {
            "iv": "kadGyMP9MbMkB1IfIKCNaA==",
            "key": "NqdGyMP9MbMiB1IfIKCNeQ==",
            "url": "xxxxxxx",
            "algorithm": "AES-128-CBC"
        },
        "preview_duration": 2,
        "multidrm": {
            "emi": 16420,
            "content_id": "jjJr6K",
            "streaming_mode": "HLS",
            "drm_list": [
                "PLAYREADY"
            ],
            "encrypt_audio": 0
        }
    }
}

Example Responses

Status code: 202

Encryption task created successfully.

{
  "task_id" : 100211
}

Status code: 400

Failed to create an encryption task.

{
  "error_code" : "MPC.10202",
  "error_msg" : "Invalid request parameter"
}

Status Codes

Status Code

Description

202

Encryption task created successfully.

400

Failed to create an encryption task.

Error Codes

See Error Codes.