# GPG 키에 대한 REST API 엔드포인트

REST API를 사용하여 인증된 사용자의 GPG 키를 관리합니다.

## 사용자 GPG 키 관리 정보

`public_key` 응답 필드에 반환된 데이터는 GPG 형식의 키가 아닙니다. 사용자가 GPG 키를 업로드하면 구문 분석되며 암호화 퍼블릭 키가 추출되고 저장됩니다. 이 암호화 키는 이 범주의 엔드포인트가 반환하는 키입니다. 이 키는 GPG와 같은 프로그램에서 직접 사용하기에 적합하지 않습니다.

요청 URL에 `{username}` 매개 변수가 포함되어 있지 않으면 응답은 로그인한 사용자에 대한 것입니다(요청과 함께 [인증 정보](/ko/enterprise-server@3.22/rest/authentication/authenticating-to-the-rest-api)를 전달해야 함). 사용자가 2단계 인증을 사용하도록 설정했는지 여부와 같은 추가 개인 정보는 기본 인증 또는 범위를 사용하여 OAuth  를 통해`user` 인증될 때 포함됩니다.

> \[!NOTE]
> Most endpoints use `Authorization: Bearer <YOUR-TOKEN>` and `Accept: application/vnd.github+json` headers, plus `X-GitHub-Api-Version: 2026-03-10`. Curl examples below omit these standard headers for brevity.

## List GPG keys for the authenticated user

```
GET /user/gpg_keys
```

Lists the current user's GPG keys.
OAuth app tokens and personal access tokens (classic) need the read:gpg\_key scope to use this endpoint.

### Parameters

#### Headers

* **`accept`** (string)
  Setting to `application/vnd.github+json` is recommended.

#### Path and query parameters

* **`per_page`** (integer)
  The number of results per page (max 100). For more information, see "Using pagination in the REST API."
  Default: `30`

* **`page`** (integer)
  The page number of the results to fetch. For more information, see "Using pagination in the REST API."
  Default: `1`

### HTTP response status codes

* **200** - OK

* **304** - Not modified

* **401** - Requires authentication

* **403** - Forbidden

* **404** - Resource not found

### Code examples

#### Example

**Request:**

```curl
curl -L \
  -X GET \
  http(s)://HOSTNAME/api/v3/user/gpg_keys
```

**Response schema (Status: 200):**

Array of `GPG Key`:

* `id`: required, integer, format: int64
* `name`: string or null
* `primary_key_id`: required, integer or null
* `key_id`: required, string
* `public_key`: required, string
* `emails`: required, array of objects:
  * `email`: string
  * `verified`: boolean
* `subkeys`: required, array of objects:
  * `id`: integer, format: int64
  * `primary_key_id`: integer
  * `key_id`: string
  * `public_key`: string
  * `emails`: array of objects:
    * `email`: string
    * `verified`: boolean
  * `subkeys`: array of object
  * `can_sign`: boolean
  * `can_encrypt_comms`: boolean
  * `can_encrypt_storage`: boolean
  * `can_certify`: boolean
  * `created_at`: string
  * `expires_at`: string or null
  * `raw_key`: string or null
  * `revoked`: boolean
* `can_sign`: required, boolean
* `can_encrypt_comms`: required, boolean
* `can_encrypt_storage`: required, boolean
* `can_certify`: required, boolean
* `created_at`: required, string, format: date-time
* `expires_at`: required, string or null, format: date-time
* `revoked`: required, boolean
* `raw_key`: required, string or null

## Create a GPG key for the authenticated user

```
POST /user/gpg_keys
```

Adds a GPG key to the authenticated user's GitHub account.
OAuth app tokens and personal access tokens (classic) need the write:gpg\_key scope to use this endpoint.

### Parameters

#### Headers

* **`accept`** (string)
  Setting to `application/vnd.github+json` is recommended.

#### Body parameters

* **`name`** (string)
  A descriptive name for the new key.

* **`armored_public_key`** (string) (required)
  A GPG key in ASCII-armored format.

### HTTP response status codes

* **201** - Created

* **304** - Not modified

* **401** - Requires authentication

* **403** - Forbidden

* **404** - Resource not found

* **422** - Validation failed, or the endpoint has been spammed.

### Code examples

#### Example

**Request:**

```curl
curl -L \
  -X POST \
  http(s)://HOSTNAME/api/v3/user/gpg_keys \
  -d '{
  "name": "Octocat's GPG Key",
  "armored_public_key": "-----BEGIN PGP PUBLIC KEY BLOCK-----\nVersion: GnuPG v1\n\nmQINBFnZ2ZIBEADQ2Z7Z7\n-----END PGP PUBLIC KEY BLOCK-----"
}'
```

**Response schema (Status: 201):**

* `id`: required, integer, format: int64
* `name`: string or null
* `primary_key_id`: required, integer or null
* `key_id`: required, string
* `public_key`: required, string
* `emails`: required, array of objects:
  * `email`: string
  * `verified`: boolean
* `subkeys`: required, array of objects:
  * `id`: integer, format: int64
  * `primary_key_id`: integer
  * `key_id`: string
  * `public_key`: string
  * `emails`: array of objects:
    * `email`: string
    * `verified`: boolean
  * `subkeys`: array of object
  * `can_sign`: boolean
  * `can_encrypt_comms`: boolean
  * `can_encrypt_storage`: boolean
  * `can_certify`: boolean
  * `created_at`: string
  * `expires_at`: string or null
  * `raw_key`: string or null
  * `revoked`: boolean
* `can_sign`: required, boolean
* `can_encrypt_comms`: required, boolean
* `can_encrypt_storage`: required, boolean
* `can_certify`: required, boolean
* `created_at`: required, string, format: date-time
* `expires_at`: required, string or null, format: date-time
* `revoked`: required, boolean
* `raw_key`: required, string or null

## Get a GPG key for the authenticated user

```
GET /user/gpg_keys/{gpg_key_id}
```

View extended details for a single GPG key.
OAuth app tokens and personal access tokens (classic) need the read:gpg\_key scope to use this endpoint.

### Parameters

#### Headers

* **`accept`** (string)
  Setting to `application/vnd.github+json` is recommended.

#### Path and query parameters

* **`gpg_key_id`** (integer) (required)
  The unique identifier of the GPG key.

### HTTP response status codes

* **200** - OK

* **304** - Not modified

* **401** - Requires authentication

* **403** - Forbidden

* **404** - Resource not found

### Code examples

#### Example

**Request:**

```curl
curl -L \
  -X GET \
  http(s)://HOSTNAME/api/v3/user/gpg_keys/GPG_KEY_ID
```

**Response schema (Status: 200):**

Same response schema as [Create a GPG key for the authenticated user](#create-a-gpg-key-for-the-authenticated-user).

## Delete a GPG key for the authenticated user

```
DELETE /user/gpg_keys/{gpg_key_id}
```

Removes a GPG key from the authenticated user's GitHub account.
OAuth app tokens and personal access tokens (classic) need the admin:gpg\_key scope to use this endpoint.

### Parameters

#### Headers

* **`accept`** (string)
  Setting to `application/vnd.github+json` is recommended.

#### Path and query parameters

* **`gpg_key_id`** (integer) (required)
  The unique identifier of the GPG key.

### HTTP response status codes

* **204** - No Content

* **304** - Not modified

* **401** - Requires authentication

* **403** - Forbidden

* **404** - Resource not found

* **422** - Validation failed, or the endpoint has been spammed.

### Code examples

#### Example

**Request:**

```curl
curl -L \
  -X DELETE \
  http(s)://HOSTNAME/api/v3/user/gpg_keys/GPG_KEY_ID
```

**Response schema (Status: 204):**

## List GPG keys for a user

```
GET /users/{username}/gpg_keys
```

Lists the GPG keys for a user. This information is accessible by anyone.

### Parameters

#### Headers

* **`accept`** (string)
  Setting to `application/vnd.github+json` is recommended.

#### Path and query parameters

* **`username`** (string) (required)
  The handle for the GitHub user account.

* **`per_page`** (integer)
  The number of results per page (max 100). For more information, see "Using pagination in the REST API."
  Default: `30`

* **`page`** (integer)
  The page number of the results to fetch. For more information, see "Using pagination in the REST API."
  Default: `1`

### HTTP response status codes

* **200** - OK

### Code examples

#### Example

**Request:**

```curl
curl -L \
  -X GET \
  http(s)://HOSTNAME/api/v3/users/USERNAME/gpg_keys
```

**Response schema (Status: 200):**

Same response schema as [List GPG keys for the authenticated user](#list-gpg-keys-for-the-authenticated-user).