private static void ImportKeyMaterial(KmsClient kmsClient, string keyId)
        {
            var importToken          = "AACIBjIzZTI1Mzk2LTQwMGItNDA0Mi1hNmYzLTM2YmRiYTIwYmU2ZQAA4Q9F+dVOE6dapktmmmZGhNeqQYj7QRqK4BTeqx56q48jSf+bPXqrpqJXvdVvoXvyMAaA9QL2r9GvV94abmRFNgO32+P+1VKNDLNPIfEaLcLKg4bloVEvBpLvek1e/60bSRQc5MNvWkpfJR9bBDNYLhJgrPdqp7Vkqt9oK827pn3rL5qhoKPMn6Zod2GwYMjvFyyFHlhNM4LaGFGeZe+pO3YIj7RHcm8iAEpMZsewoOkISNY2ZahZHa1cAg8DMX95uq5rolgO3HNtWam8SBo0YbKy+a+hyM8S9Vcs0z3mc/j+nVpFfp7NzfaJQK56mjNkiqGbhiqmcYltcuazNiRHYF+b/NSNKLtD6SdEUdjrolG9ObDnlDmQb42Onr2GDa40y+ALYx29xxrlz7QSL1UhrC6qmjqRHD8O3BP4+YKEzNUB/kqER1F11dVCmc5PYFs6JdiM5AQBLbj1bwBQ7T+i9JOEzynyJfuRl02nwL2znFSDVf91uPnHzr6qjJdCXmDL2X30Rb6Y7H8Ss4BgP5FsZeusMwKLCtzWuYyK3KQvYSBDfw92+TH28R4mKm2CsB+6r1rx2LowrsHDwFuQLDIgG14xoNgaDYqdIdOk6OhxPFnG3PKekbCfaScQvzAkNJDZea65dSc06Vnv+E0T/aW6QYOI59T0jJmFjs6/KOBToN2pKxiHMiXBbo79Op4oetreUI+fKipu5HMO4uI1SGNBZHajhHpZVrqaYp6Pcdh5t7gqdmjeAYykBvEskjrLs02Vc0SiX0qneXy9+TiwAedDut0CHTChU53dGi8n3hE8EsP+DRPIPDcxrWri1pEvdM25GM9teUU++/yeQ2DinAMlREvOy+w/OtVZIRmAjKLm0p/ZIw4f57kv05Axk4O5mih1Lg5PksQGDOW1uOVpvKrAxDELl9o1bQuS8PymwF7gG1YmQu2wj4soYvuGdzm4u9mIgJDN84++smqHYeEjfP4PCMAW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qBhb/Zyk4eSReVZp+5Rf+x9MioXz+lIBpDRPtkq91P8IZQt49mU41H8hoEXhoxYW2kIt82AvHCfWy0goR67RLq4VxkRVggK3RqsdQ6jD0TC0gvCQ96nIuGXL0qrPT81yAI5fw8=";
            var encryptedKeyMaterial = "C6aqYsmfRjLGGkCxE9Wzm9rqc2yuOJZI4um5jSYHLebEzNyvXfX0Uk8Jkw5806S2IaW+n2gv6+K6hVqKDAzol5P8ycZRv/zvpvzgRjgbNMoFZz7xodsOXAHR+o5qZoeszoSYbLwWUt64/DSg68KxrgSYRO2H/03ROx+yCYKypJmsBlHWAg6AnnQQoxn6Ez5kDqTJKBNfMah8JibwcGU9+BuTr2WfWslqEa5LoMjc9HKPpTR1qh97e92VeGZ7JJ6ofODskNzJwj1jg1GTaBUqp6rBQmXaITmphcQt0/4aoxEqlgrgYLHX/Sxo3xwpRqZMFR7c4hFqM4lzSi1C21uxyQ==";

            try
            {
                var req = new ImportKeyMaterialRequest
                {
                    VersionId = "v1.0",
                    Body      = new ImportKeyMaterialRequestBody
                    {
                        KeyId                = keyId,
                        ImportToken          = importToken,
                        EncryptedKeyMaterial = encryptedKeyMaterial
                    }
                };
                var resp = kmsClient.ImportKeyMaterial(req);
                Console.WriteLine(resp.HttpStatusCode);
            }
            catch (RequestTimeoutException requestTimeoutException)
            {
                Console.WriteLine(requestTimeoutException.ErrorMessage);
            }
            catch (ServiceResponseException clientRequestException)
            {
                Console.WriteLine(clientRequestException.HttpStatusCode);
                Console.WriteLine(clientRequestException.ErrorCode);
                Console.WriteLine(clientRequestException.ErrorMsg);
            }
            catch (ConnectionException connectionException)
            {
                Console.WriteLine(connectionException.ErrorMessage);
            }
        }
예제 #2
0
        /// <summary>
        /// 导入密钥材料
        /// </summary>
        public async Task <ImportKeyMaterialResponse> ImportKeyMaterialAsync(ImportKeyMaterialRequest importKeyMaterialRequest)
        {
            Dictionary <string, string> urlParam = new Dictionary <string, string>();

            urlParam.Add("version_id", importKeyMaterialRequest.VersionId.ToString());
            string              urlPath  = HttpUtils.AddUrlPath("/{version_id}/{project_id}/kms/import-key-material", urlParam);
            SdkRequest          request  = HttpUtils.InitSdkRequest(urlPath, "application/json;charset=UTF-8", importKeyMaterialRequest);
            HttpResponseMessage response = await DoHttpRequestAsync("POST", request);

            return(JsonUtils.DeSerializeNull <ImportKeyMaterialResponse>(response));
        }
예제 #3
0
        /// <summary>
        /// 用于导入密钥材料。只有类型为EXTERNAL 的CMK 才可以导入,导入的密钥材料使用 GetParametersForImport 获取的密钥进行加密。可以为指定的 CMK 重新导入密钥材料,并重新指定过期时间,但必须导入相同的密钥材料。CMK 密钥材料导入后不可以更换密钥材料。导入的密钥材料过期或者被删除后,指定的CMK将无法使用,需要再次导入相同的密钥材料才能正常使用。CMK是独立的,同样的密钥材料可导入不同的 CMK 中,但使用其中一个 CMK 加密的数据无法使用另一个 CMK解密。
        /// 只有Enabled 和 PendingImport状态的CMK可以导入密钥材料。
        /// </summary>
        /// <param name="req"><see cref="ImportKeyMaterialRequest"/></param>
        /// <returns><see cref="ImportKeyMaterialResponse"/></returns>
        public ImportKeyMaterialResponse ImportKeyMaterialSync(ImportKeyMaterialRequest req)
        {
            JsonResponseModel <ImportKeyMaterialResponse> rsp = null;

            try
            {
                var strResp = this.InternalRequestSync(req, "ImportKeyMaterial");
                rsp = JsonConvert.DeserializeObject <JsonResponseModel <ImportKeyMaterialResponse> >(strResp);
            }
            catch (JsonSerializationException e)
            {
                throw new TencentCloudSDKException(e.Message);
            }
            return(rsp.Response);
        }