

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

# 重新加密已加密的物件
<a name="reencrypting-an-encrypted-object"></a>

在一個 KMS 金鑰下加密的現有客戶加密文字可透過重新加密命令將其重新加密為另一個 KMS 金鑰。使用新的 KMS 金鑰在伺服器端重新加密資料，而不暴露在用戶端的金鑰純文字。資料會先解密，然後加密。

以下是請求語法。

```
{
	"CiphertextBlob": "blob",
	"DestinationEncryptionContext": { "string" : "string" },
	"DestinationKeyId": "string",
	"GrantTokens": ["string"],
       "SourceKeyId": "string",
	"SourceEncryptionContext": { "string" : "string"}
}
```

請求接受採用 JSON 格式的下列資料。

**CiphertextBlob**  
要重新加密的資料加密文字。

** DestinationEncryptionContext**  
(選用) 重新加密資料時要使用的加密內容。

**DestinationKeyId**  
用來重新加密資料之金鑰的金鑰 ID。

**GrantTokens**  
(選用) 授予字符清單，代表授予提供執行解密的許可。

**SourceKeyId**  
(選用) 用於解密資料之金鑰的金鑰識別符。

**SourceEncryptionContext**  
(選用) 用於加密和解密 `CiphertextBlob` 參數中指定資料的加密內容。

該過程結合了先前描述的解密和加密操作：客戶加密文字在客戶加密文字所參考的初始 HBK 下解密至預期 KMS 金鑰下的當前 HBK。當此命令中使用的 KMS 金鑰相同時，此命令會將客戶加密文字從舊版的 HBK 移至最新版本的 HBK。

以下是回應語法。

```
{
    "CiphertextBlob": blob,
    "DestinationEncryptionAlgorithm": "string",
    "KeyId": "string",
    "SourceEncryptionAlgorithm": "string",
    "SourceKeyId": "string"
}
```

如果呼叫的應用程式想要確保基礎純文字的真實性，則必須驗證傳回的 SourceKeyId 是預期的。