

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 使用 KMU 設定 AWS CloudHSM 金鑰的屬性
<a name="key_mgmt_util-setAttribute"></a>

使用 AWS CloudHSM key\_mgmt\_util 中的 **setAttribute**命令，將僅在目前工作階段中有效的金鑰轉換為持久性金鑰，直到您將其刪除為止。在作法上，此命令將金鑰的字符屬性值 (`OBJ_ATTR_TOKEN`) 從 false (`0`) 變更為 true (`1`)。您只能變更您自己金鑰的屬性。

您也可以使用 cloudhsm\_mgmt\_util 中的 **setAttribute** 命令，以變更標籤、包裝、取消包裝、加密和解密屬性。

執行任何 key\_mgmt\_util 命令之前，您必須先[啟動 key\_mgmt\_util](key_mgmt_util-setup.md#key_mgmt_util-start) 並以加密使用者 (CU) 的身分[登入](key_mgmt_util-log-in.md) HSM。

## 語法
<a name="setAttribute-syntax"></a>

```
setAttribute -h 

setAttribute -o {{<object handle>}} 
             -a 1
```

## 範例
<a name="setAttribute-examples"></a>

此範例示範如何將工作階段金鑰轉換為持久性金鑰。

第一個命令使用 [genSymKey](key_mgmt_util-genSymKey.md) 的 `-sess`參數，以建立只在目前工作階段中有效的 192 位元 AES 金鑰。輸出顯示新工作階段金鑰的金鑰控制代碼是 `262154`。

```
Command: genSymKey -t 31 -s 24 -l tmpAES -sess
      
        Cfm3GenerateSymmetricKey returned: 0x00 : HSM Return: SUCCESS

        Symmetric Key Created.  Key Handle: 262154

        Cluster Error Status
        Node id 1 and err state 0x00000000 : HSM Return: SUCCESS
```

此命令使用 [findKey](key_mgmt_util-findKey.md) 來尋找目前工作階段中的工作階段金鑰。輸出確認金鑰 `262154` 是工作階段金鑰。

```
Command:  findKey -sess 1

Total number of keys present 1

 number of keys matched from start index 0::0
262154

        Cluster Error Status
        Node id 1 and err state 0x00000000 : HSM Return: SUCCESS
        Node id 0 and err state 0x00000000 : HSM Return: SUCCESS

        Cfm3FindKey returned: 0x00 : HSM Return: SUCCESS
```

此命令使用 **setAttribute**，以將金鑰 `262154` 從工作階段金鑰轉換為持久性金鑰。在作法上，此命令將金鑰的權杖屬性值 (`OBJ_ATTR_TOKEN`) 從 `0` (false) 變更為 `1` (true)。如需金錀屬性的解譯說明，請參閱 [AWS CloudHSM KMU 的金鑰屬性參考](key-attribute-table.md)。

此命令使用 `-o` 參數來指定金鑰控制代碼 (`262154`)，並使用 `-a` 參數來指定代表字符屬性的常數 (`1`)。執行此命令時會提示您輸入字符屬性的值。唯一的有效值是 `1` (true)，此值代表持久性金鑰。

```
Command: setAttribute -o 262154 -a 1
         This attribute is defined as a boolean value.
          Enter the boolean attribute value (0 or 1):1

        Cfm3SetAttribute returned: 0x00 : HSM Return: SUCCESS

        Cluster Error Status
        Node id 1 and err state 0x00000000 : HSM Return: SUCCESS
        Node id 0 and err state 0x00000000 : HSM Return: SUCCESS
```

為了確認金鑰 `262154` 現在是持久性，此命令使用 **findKey** 來搜尋工作階段金鑰 (`-sess 1`) 和持久性金鑰 (`-sess 0`)。這一次，命令不會尋找任何工作階段金鑰，而是傳回在持久性金鑰清單中的 `262154`。

```
Command: findKey -sess 1

Total number of keys present 0

        Cluster Error Status
        Node id 1 and err state 0x00000000 : HSM Return: SUCCESS
        Node id 0 and err state 0x00000000 : HSM Return: SUCCESS

        Cfm3FindKey returned: 0x00 : HSM Return: SUCCESS



Command: findKey -sess 0

Total number of keys present 5

 number of keys matched from start index 0::4
6, 7, 524296, 9, 262154

        Cluster Error Status
        Node id 1 and err state 0x00000000 : HSM Return: SUCCESS
        Node id 0 and err state 0x00000000 : HSM Return: SUCCESS

        Cfm3FindKey returned: 0x00 : HSM Return: SUCCESS
```

## Parameters
<a name="setAttribute-parameters"></a>

**-h**  
顯示命令的說明。  
必要：是

**-o**  
指定目標金鑰的金鑰控制代碼。每一個命令中只能指定一個金鑰。若要取得金鑰的金鑰控制代碼，請使用 [findKey](key_mgmt_util-findKey.md)。  
必要：是

**-a**  
指定常數，其代表您要變更的屬性。唯一的有效值是 `1`，這代表字符屬性 `OBJ_ATTR_TOKEN`。  
如要取得屬性及其整數值，請使用 [listAttributes](key_mgmt_util-listAttributes.md)。  
必要：是

## 相關主題
<a name="setAttribute-seealso"></a>
+ cloudhsm\_mgmt\_util 中的 [setAttribute](cloudhsm_mgmt_util-setAttribute.md)
+ [getAttribute](key_mgmt_util-getAttribute.md)
+ [listAttributes](key_mgmt_util-listAttributes.md)
+ [金錀屬性參考](key-attribute-table.md)