> 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/b215c1cdc38b5a5c8b52e41bfb84ce9d8eaf4b7b" 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

> #### 注記
>
> セキュリティ強化のため、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.
