全部產品
Search
文件中心

Key Management Service:EncryptionContext說明

更新時間:Jul 06, 2024

EncryptionContext是在KMS的Encrypt、GenerateDataKey、Decrypt等API中可能用到的JSON字串。

EncryptionContext的作用

EncryptionContext只能是String-String形式的JSON字串,用於保護資料的完整性。

如果加密(Encrypt、GenerateDataKey)時指定了該參數,解密(Decrypt)密文時,需要傳入等價的EncryptionContext參數,才能正確的解密。EncryptionContext雖然與解密相關,但是並不會存在密文(CipherBlob)中。

EncryptionContext有效值

EncryptionContext的有效值是一個總長度在8192個字元數以內的JSON字串,並且只能是String-String形式。當您直接調用API填寫EncryptionContext時,請注意轉義問題。

有效EncryptionContext樣本

{"ValidKey":"ValidValue"}
{"Key1":"Value1","Key2":"Value2"}
            

無效的EncryptionContext(部分)樣本

[{"Key":"Value"}] //JSON數組
{"Key":12345} //String-int
{"Key":["value1","value2"]} //String-數組
            

等價的EncryptionContext

EncryptionContext的本質是一個String-String的map(hashtable), 因此在作為參數時,只需要保證JSON字串所表示的key-value含義是一致的,則EncryptionContext是等價的。與加密時輸入的EncryptionContext等價的EncryptionContext即可用於正確的解密,而不用保持完全一致的字串。

等價的EncryptionContext樣本

{"Key1":"Value1","Key2":"Value2"} 與 {"Key2":"Value2","Key1":"Value1"} 等價