

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 使用 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>

此示例说明如何将会话密钥转换为持久密钥。

第一个命令使用`-sess`参数创建仅在当前会话中有效的 192 位 AES 密钥。[genSymKey](key_mgmt_util-genSymKey.md)输出显示新会话密钥的密钥句柄为 `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
```

## 参数
<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)