> For the complete documentation index, see [llms.txt](https://docs.payments.thalescloud.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.payments.thalescloud.io/pin-management/ja/pinwosuru/pinwosuru-1.md).

# PINを変更する

物理カード内でPINの露出を制限するため、イシュアアプリケーションはPIN変更の作業をD1 SDKに委譲します。

現在サポートされている（イシュアバックエンドからの）PINフォーマットは次のとおりです：

* PIN ISO0
* PIN 3DES Seccos

### ユーザーエクスペリエンス

<figure><img src="/files/c275c6efe93fb632c046d47434aca3062772fffd" alt=""><figcaption><p>イシュアアプリケーションのサンプルPIN変更画面</p></figcaption></figure>

### フロー

<figure><img src="/files/ffb5f70f2919766d4e48369d34e5f9916aa27c1a" alt=""><figcaption><p>PINを変更するためのハイレベルフロー</p></figcaption></figure>

1. ユーザーはバンキングアプリで認証し、PIN変更を要求します
2. SDKへの内部呼び出しが行われます
3. PINを安全に入力する
4. D1 バックエンド API
5. D1はデバイス鍵からイシュア鍵へPINを変換暗号化します
6. PINをイシュアのバックエンドに設定する

### シーケンス図

#### 前提条件

* コンシューマー、口座、およびカードがすでにD1に登録されていること
* SDKが適切に初期化されていること
* イシュアアプリがD1 SDKのログインAPIを呼び出していること。

<figure><img src="/files/ccf6adb8d3d876fe54fb398093af9f17b30d6f22" alt=""><figcaption><p>PIN変更のためのシーケンス図</p></figcaption></figure>

<figure><img src="/files/afc8520c87bb5ad5a97f83e745d30889590ad538" alt=""><figcaption></figcaption></figure>

### 必要なAPI

| API                                                                                                                                              | インバウンド／アウトバウンド    | 説明                                         |
| ------------------------------------------------------------------------------------------------------------------------------------------------ | ----------------- | ------------------------------------------ |
| [承認トークンを取得](/pin-management/ja/d1-apiwosuru/d1-apirifarensu/autobaundoapid1kara/oauth2-api.md#post-oauth2-token)                                 | イシュア <- Thales D1 | イシュアバックエンドを呼び出すためのOAuth 2.0アクセストークンを取得します。 |
| [PIN設定](/pin-management/ja/d1-apiwosuru/d1-apirifarensu/autobaundoapid1kara/pin-guan-li-api.md#put-cms-api-v1-issuers-issuerid-cards-cardid-pin) | イシュア <- Thales D1 | モバイルアプリからイシュアのバックエンドにPINを設定します。            |

### 条件付きAPI

| API                                                                                                                                                                      | インバウンド／アウトバウンド    | 説明                                              |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----------------- | ----------------------------------------------- |
| [PIN変更カウンター取得API](/pin-management/ja/d1-apiwosuru/d1-apirifarensu/autobaundoapid1kara/pin-guan-li-api.md#get-cms-api-v1-issuers-issuerid-cards-cardid-pin-changecounter) | イシュア <- Thales D1 | PIN Seccosの場合。PIN計算に必要なPIN変更カウンターを取得するために使用されます |

### SDK

> #### 注意
>
> セキュリティ強化のため、Change PIN APIは他のAPIよりも既定でより厳格な最終ログインタイムアウト期間を持っています。PIN変更を成功させるには、PIN変更を送信する前に割り当てられた時間内にログイン／再ログインフローを完了するように管理する必要があります。

{% tabs %}
{% tab title="Android" %}

```java
@Nullable
@Override
public View onCreateView(
        @NonNull LayoutInflater inflater,
        @Nullable ViewGroup container,
        @Nullable Bundle savedInstanceState
) {
    View view = inflater.inflate(R.layout.fragment_main, container, false);

    SecureEditText entryEditPin = (SecureEditText)view.findViewById(R.id.pin_entry);
    SecureEditText confirmEditPin = (SecureEditText)view.findViewById(R.id.pin_confirm);
    PINEntryUI.PINEventListener listener = new PINEntryUI.PINEventListener() {
        @Override
        public void onPinEvent(PINEntryUI.PINEvent pinEvent, String additionalInfo) {
            switch (pinEvent){
                case FIRST_ENTRY_FINISH:
                    // フォーカスをconfirmEditPinに切り替える
                    break;
                case PIN_MATCH:
                    // 続行／送信ボタンを有効にする
                    break;
                case PIN_MISMATCH:
                    // 続行／送信ボタンを無効にし、PIN_MISMATCHのエラーを表示する
                    break;
            }
        }
    };

    String cardID = ""; // 例：サーバーから取得
    ChangePINOptions options = new ChangePINOptions(4);
    pinEntryUI = d1Task.changePIN(cardID, entryEditPin, confirmEditPin, options, listener);

    Button button = (Button)view.findViewById(R.id.pin_submit);
    button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            pinEntryUI.submit(new D1Task.Callback<Void>() {
                @Override
                public void onSuccess(final Void data) {
                }

                @Override
                public void onError(@NonNull final D1Exception exception) {
                }
            });
        }
    });
    
    return view;
}
```

{% endtab %}

{% tab title="iOS" %}

```swift
class ViewController: UIViewController {
    var pinEntryUI: PINEntryUI? = nil
    override func viewDidLoad() {
        let entryEditPin = D1SecureTextField()
        let confirmEditPin = D1SecureTextField()
        let cardID = "" // 例：サーバーから取得
        let options = ChangePINOptions(pinLength: 4)
        pinEntryUI = d1Task.changePIN(cardID, textFieldNew: entryEditPin, textFieldConfirm: confirmEditPin, options: options, delegate: self)
    }

    func onButtonClick() {
        pinEntryUI?.submit { error in 
        }
    }
}

extension ViewController: PINEntryUIDelegate {
    func pinEntryUI(_ pinEntryUI: PINEntryUI, pinEvent: PINEntryUI.PINEvent, additionalInfo: String) {
        switch pinEvent {
            case .firstEntryFinish: 
                // フォーカスをconfirmEditPinに切り替える
                break
            case .pinMismatch:
                // 続行／送信ボタンを有効にする
                break
            case .pinMatch:
                // 続行／送信ボタンを無効にし、PIN_MISMATCHのエラーを表示する
                break
        }
    }
}

```

{% endtab %}
{% endtabs %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.payments.thalescloud.io/pin-management/ja/pinwosuru/pinwosuru-1.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
