Updated on 2026-09-21 GMT+08:00

Accessing the page for importing private keys

Function

This API is used to import a private key to a specified key pair.

Calling Method

For details, see Calling APIs.

URI

POST /v3/{project_id}/keypairs/private-key/import

Table 1 Path Parameters

Parameter

Mandatory

Type

Description

project_id

Yes

String

Definition

Project ID. For details, see Obtaining a Project ID.

Constraints

N/A

Range

The value returned by the IAM API is used, which contains 32 characters.

Default Value

N/A

Request Parameters

Table 2 Request header parameters

Parameter

Mandatory

Type

Description

X-Auth-Token

Yes

String

Definition

User token. It can be obtained by calling the IAM API. The value of X-Subject-Token in the response header is the user token.

Constraints

N/A

Range

Obtain the value by calling the IAM API for obtaining the user token.

Default Value

N/A

Table 3 Request body parameters

Parameter

Mandatory

Type

Description

keypair

Yes

ImportPrivateKeyKeypairBean object

Definition

Information about the key pair to be imported

Constraints

N/A

Range

N/A

Default Value

N/A

Table 4 ImportPrivateKeyKeypairBean

Parameter

Mandatory

Type

Description

name

Yes

String

Definition

SSH key pair name

Constraints

  • The key pair name must be unique.

  • The SSH key pair name can contain at most 64 characters. Only letters, digits, underscores (_), and hyphens (-) are allowed.

Range

N/A

Default Value

N/A

user_id

No

String

Definition

ID of the user to which the SSH key pair belongs

Constraints

N/A

Range

N/A

Default Value

N/A

key_protection

Yes

ImportPrivateKeyProtection object

Definition

Hosting and protection information about the imported key

Constraints

N/A

Range

N/A

Default Value

N/A

Table 5 ImportPrivateKeyProtection

Parameter

Mandatory

Type

Description

private_key

Yes

String

Definition

Private key of the imported SSH key pair

Constraints

N/A

Range

N/A

Default Value

N/A

encryption

Yes

Encryption object

Definition

How a private key is encrypted and stored

Constraints

N/A

Range

N/A

Default Value

N/A

Table 6 Encryption

Parameter

Mandatory

Type

Description

type

Yes

String

Definition

Encryption type

Constraints

If KMS is unavailable, set this parameter to default.

Range

  • default: Default encryption mode, which applies to sites where KMS is unavailable.

  • kms: KMS encryption mode

Default Value

default

kms_key_name

No

String

Definition

KMS key name

Constraints

  • If type is set to kms, you must enter the KMS key name or ID.

Range

N/A

Default Value

N/A

kms_key_id

No

String

Definition

KMS key ID

Constraints

  • If type is set to kms, you must enter the KMS key name or ID.

Range

N/A

Default Value

N/A

Response Parameters

Status code: 200

Table 7 Response body parameters

Parameter

Type

Description

keypair

ImportPrivateKeyKeypairBean object

One

Table 8 ImportPrivateKeyKeypairBean

Parameter

Type

Description

name

String

Definition

SSH key pair name

Range

N/A

user_id

String

Definition

ID of the user to which the SSH key pair belongs

Range

N/A

key_protection

ImportPrivateKeyProtection object

Definition

Hosting and protection information about the imported key

Range

N/A

Table 9 ImportPrivateKeyProtection

Parameter

Type

Description

private_key

String

Definition

Private key of the imported SSH key pair

Range

N/A

encryption

Encryption object

Definition

How a private key is encrypted and stored

Range

N/A

Table 10 Encryption

Parameter

Type

Description

type

String

Definition

Encryption type

default.

Range

  • default: Default encryption mode, which applies to sites where KMS is unavailable.

  • kms: KMS encryption mode

default

kms_key_name

String

Definition

KMS key name

type is set to kms, you must enter the KMS key name or ID.

Range

N/A

kms_key_id

String

Definition

KMS key ID

type is set to kms, you must enter the KMS key name or ID.

Range

N/A

Example Requests

{
  "keypair" : {
    "name" : "demo2",
    "key_protection" : {
      "private_key" : "-----BEGIN RSA PRIVATE KEY-----...",
      "encryption" : {
        "type" : "kms",
        "kms_key_name" : "kps/default"
      }
    }
  }
}

Example Responses

Status code: 200

Request succeeded.

{
  "keypair" : {
    "name" : "demo2"
  }
}

Status Codes

Status Code

Description

200

Request succeeded.

Error Codes

See Error Codes.